Python Pandas Dataframe 按列排序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46072509/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:27:38  来源:igfitidea点击:

Pandas Dataframe sort by a column

pythonpandassortingdataframemultiple-columns

提问by Ayan Mitra

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

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

   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

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

我想按角度(升序)对 df 进行排序。

回答by Mohamed Ali JAMAOUI

You can use this:

你可以使用这个:

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

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

默认情况下ascending=True传递给上面的调用。有关更多信息,请查看此处的文档。