熊猫中的sort_values

时间:2020-03-29 16:35:43

标签: python pandas dataframe jupyter

我正在尝试按“百分比”对数据框的内容进行排序。排序似乎无效。

代码- enter image description here

ipl_tot['Win Percent'] = ipl_tot['Matches Won']/ipl_tot['Matches 
Played'] * 100
ipl_tot.sort_values(by = (['Matches Won', 'Win Percent']),ascending = 
False)
ipl_tot

1 个答案:

答案 0 :(得分:1)

您必须将inplace=True参数传递给sort_values函数才能就地执行操作。

替换:

ipl_tot.sort_values(by=(['Matches Won', 'Win Percent']), ascending=False)

使用方式:

ipl_tot.sort_values(by=(['Matches Won', 'Win Percent']), ascending=False, inplace=True)