0

I have the following pandas dataframe: enter image description here

and I want to change the order of index items so that the last row becomes the first row and then I get all the NaN values in the diagonal. I tried the reindex function but what I got was basically changing the order of indeces without changing the order of corresponding rows:

df.reindex(['T2S1', 'T2S2', 'T2S3', 'T2S4', 'T2O1', 'T2O2', 'T2O3', 'T2O4', 'T2SF1', 'T2SF2', 'T2SF3', 'T2OF1', 'T2OF2', 'T2OF3'])

enter image description here

amiref
  • 3,181
  • 7
  • 38
  • 62
  • Does this answer your question? [How to change the order of DataFrame columns?](https://stackoverflow.com/questions/13148429/how-to-change-the-order-of-dataframe-columns) – blau Dec 20 '22 at 16:28

1 Answers1

1

You can try:

idx = df.index
df.reindex(idx[-1:].append(idx[0:-1]))
SomeDude
  • 13,876
  • 5
  • 21
  • 44