简体   繁体   中英

pandas dataframe python - make the first row to be the last

so I have a df that looks like this:

          2019   2018
Sally    -6461  -6340
Brian     7139   7200
rebecca   1337   1067
mark     10922  11128
toto     12936  13054

But I would like to make the first row to come at last like this:

          2019   2018
Brian     7139   7200
rebecca   1337   1067
mark     10922  11128
toto     12936  13054
Sally    -6461  -6340

How to achieve this?
Thank you!!

Try with argsort

df=df.iloc[(df.index=='Sally').argsort()]
          2019   2018
Brian     7139   7200
rebecca   1337   1067
mark     10922  11128
toto     12936  13054
Sally    -6461  -6340

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM