Pandas:TypeError:sort_values() 缺少 1 个必需的位置参数:'by'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42460983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas: TypeError: sort_values() missing 1 required positional argument: 'by'
提问by ds_ro
I am facing TypeError: sort_values() missing 1 required positional argument: 'by'
我面临 TypeError: sort_values() 缺少 1 个必需的位置参数:'by'
for i in range(0,len(data_sims.index)):
for j in range(1,len(data_sims.columns)):
user = data_sims.index[i]
serial = data_sims.columns[j]
if dataUser.ix[i][j] == 1:
data_sims.ix[i][j] = 0
else:
serial_top_names = data_neighbours.ix[serial][1:10]
serial_top_sims = dataSim.ix[serial].sort_values(ascending=False)[1:10]
user_preferences = dataUser.ix[user,serial_top_names]
data_sims.ix[i][j] = getScore(user_preferences,serial_top_sims)
Detailed Error:
详细错误:
> --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () 9 else: 10 serial_top_names = data_neighbours.ix[serial][1:10] ---> 11 serial_top_sims = dataSim.ix[serial].sort_values(ascending=False)[1:10] 12 user_preferences = dataUser.ix[user,serial_top_names] 13 TypeError: sort_values() missing 1 required positional argument: 'by'
I tried using following but didn't work
我尝试使用以下但没有用
pd.DataFrame.sort_values(dataSim,ascending=[0])[1:10]
Is there anything that I'm missing?
有什么我想念的吗?
采纳答案by Grant
The documentation for Pandasmentions:
DataFrame.sort_values(by,
axis=0,
ascending=True,
inplace=False,
kind='quicksort',
na_position='last')
by: str or list of str Name or list of names which refer to the axis items.
by: str 或 str 列表 引用轴项的名称或名称列表。
In my example:
在我的例子中:
df.groupby('product').agg({'weight':'sum'}).sort_values(by='weight')
Adding by='weight' solved the TypeError: sort_values() missing 1 required positional argument: 'by'
添加 by='weight' 解决了 TypeError: sort_values() missing 1 required positional argument: 'by'