Home > Blockchain >  Changing the order of indecs and corresponding rows in a pandas dataframe
Changing the order of indecs and corresponding rows in a pandas dataframe

Time:12-22

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

CodePudding user response:

You can try:

idx = df.index
df.reindex(idx[-1:].append(idx[0:-1]))
  • Related