4

I am trying to implement the code

sort_order = {
'Documentary':0,
'Film-Noir':1,
'Biography':2,
'History':3,
'War':4,
'News':5,
'Animation':6,
'Musical':7,
'Music':8,
'Drama':9
}

df.sort_values(by=['genre'], key=lambda x: x.map(sort_order))

But I receive this error:

TypeError: sort_values() got an unexpected keyword argument 'key'

I downloaded the latest version of Pandas to try and fix this using conda update pandas but this did not change anything. I know something is going wrong because their page here shows that key should be recognized.

Any help would be greatly appreciated.

1 Answers1

5

As mentioned in the comments section, Sorting with Keys is introduced in version 1.1.0.

You may run the following to update the package (note the -U flag):

python -m pip install -U pandas
Tibebes. M
  • 6,940
  • 5
  • 15
  • 36