【问题标题】:sort_values in Pandas [duplicate]Pandas 中的 sort_values [重复]
【发布时间】:2020-07-10 01:08:00
【问题描述】:

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

代码- 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

【问题讨论】:

  • 您需要重新分配数据框或在sort_values 方法中添加inplace=True 参数。

标签: python pandas dataframe jupyter


【解决方案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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-07
    • 2020-04-30
    • 2019-01-23
    • 2020-05-06
    • 1970-01-01
    • 2017-06-06
    • 2018-06-03
    相关资源
    最近更新 更多