小编Bio*_*277的帖子

为什么“key”是 sort_values() 的意外关键字

我正在尝试实现代码

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))
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

TypeError: sort_values() got an unexpected keyword argument 'key'
Run Code Online (Sandbox Code Playgroud)

我下载了最新版本的 Pandas 来尝试使用 conda update pandas 修复此问题,但这并没有改变任何内容。我知道出了问题,因为他们的页面显示应该识别密钥。

任何帮助将不胜感激。

python sorting typeerror dataframe pandas

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1

sorting ×1

typeerror ×1