熊猫,Sort_Values排序不正确

时间:2020-08-21 01:34:20

标签: pandas

我正在尝试对数据框进行排序。

df_sorted = df.sort_values(by='PTS', ascending=False)
print(df_sorted['PTS'])

它无法正常工作,我的数据框为93行,但没有对其进行排序。

enter image description here

1 个答案:

答案 0 :(得分:2)

您的列应为字符串,让我们先将其转换为数字

df.PTS = pd.to_numeric(df.PTS)
df_sorted = df.sort_values(by='PTS', ascending=False)