reverse dataframe's rows' order with pandas [duplicate]

佐手、 提交于 2019-12-05 17:16:28

问题


How can I reverse the order of the rows in my 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:

   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.


回答1:


Check out http://pandas.pydata.org/pandas-docs/stable/indexing.html

You can do

reversed_df = df.iloc[::-1]


来源:https://stackoverflow.com/questions/35240528/reverse-dataframes-rows-order-with-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!