pandas 数据框按列排序 [英] Pandas Dataframe sort by a column

查看:60
本文介绍了 pandas 数据框按列排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python Pandas数据框. df有2列,我想按第二列对df进行排序.

I have a Python Pandas Data Frame. The df has 2 columns, I would like to sort the df by the second column.

   Kappa_prod   Angle
0   0.004511    -5.457840
1   0.003977    -5.312861
2   0.004476    -5.311292
3   0.003644    -117.579594
4   0.003306    -117.542817

我想按角度对df排序(升序).

I would like to sort the df by Angle (ascending order).

推荐答案

您可以使用:

df.sort_values("Angle", inplace=True)

默认情况下,ascending=True被传递给上述调用.有关更多信息,请在文档此处.

By default ascending=True is passed to the above call. For more information check the documentation here.

这篇关于 pandas 数据框按列排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆