pandas 使用熊猫反转数据框的行顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35240528/
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
reverse dataframe's rows' order with pandas
提问by valentin
How can I reverse the order of the rows in my pandas.dataframe?
如何反转我的pandas.dataframe中的行顺序?
I've looked everywhere and the only thing people are talking about is sorting the columns, reversing the order of the columns...
我到处看,唯一的事情人们都在谈论的排序列,扭转了顺序列...
What I want is simple :
我想要的很简单:
If my DataFrame looks like this:
如果我的 DataFrame 看起来像这样:
A B C
------------------
LOVE IS ALL
THAT MAT TERS
I want it to become this:
我希望它变成这样:
A B C
------------------
THAT MAT TERS
LOVE IS ALL
I know I can iterate over my data in reverse order but that's not what I want.
我知道我可以以相反的顺序迭代我的数据,但这不是我想要的。
回答by Mike Graham
Check out http://pandas.pydata.org/pandas-docs/stable/indexing.html
查看http://pandas.pydata.org/pandas-docs/stable/indexing.html
You can do
你可以做
reversed_df = df.iloc[::-1]