我正在尝试实现代码
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))
但是我收到了这个错误:
TypeError: sort_values() got an unexpected keyword argument 'key'
我下载了最新版本的Pandas,尝试使用conda update pandas来修复这个问题,但这并没有改变任何事情。我知道出了什么问题,因为他们的页面here显示密钥应该被识别。
任何帮助都将不胜感激。
发布于 2020-11-01 14:16:44
正如评论部分中提到的,Sorting with Keys is introduced in version 1.1.0。
您可以运行以下命令来更新包(请注意-U
标志):
python -m pip install -U pandas
https://stackoverflow.com/questions/64629100
复制相似问题