Luggie
Luggie

Reputation: 381

pandas deprecated warning to_dict()

I'm getting this deprecated warning:

Using short name for 'orient' is deprecated. Only the options: ('dict', list, 'series', 'split', 'records', 'index') will be used in a future version. Use one of the above to silence this warning.

when using any of these lines:

df.to_dict('records')
df.to_dict(orient='records')
df.to_dict(orientation='records')

pandas v1.1.3 python v3.7.1

Upvotes: 13

Views: 11939

Answers (4)

m-sarabi
m-sarabi

Reputation: 2295

As of Python 3.12.3 and pandas 2.2.2, the following lines run without any warnings:

df.to_dict('records')
df.to_dict(orient='records')

Upvotes: 0

pearl51
pearl51

Reputation: 11

I had the same warning when I used this code line: df.to_dict('records') but when I tried df.to_dict(orient = 'records'), the warning went away.

Upvotes: 1

Sergey Skripko
Sergey Skripko

Reputation: 374

I was confused with the same warning. Later I found I used "record" instead of "records". In any case, you can insert print(orient) line in the file "pandas/core/frame.py" at a line near 1485 right before the warning.

Upvotes: 5

MUK
MUK

Reputation: 411

Warning says that "orient" is deprecated. use it like this:

df.to_dict('records')

Instead of using orient='', use any of these directly ('dict', list, 'series', 'split', 'records', 'index'), like:

df.to_dict('dict')

df.to_dict('list')

Upvotes: 10

Related Questions