I have following dataframe:
(Index) sample reads yeasts
9 CO ref 10
10 CO raai 20
11 CO tus 30
I want to change the order of the columns based on sample
, expected output:
(Index) sample reads yeasts
9 CO ref 10
11 CO tus 30
10 CO raai 10
I'm not interested in the Index of the rows.
I've tried following code based on other stackoverflow/google posts:
df=df.reindex(["CO ref","CO tus","CO raai"])
This correctly changes the index, but all the other columns get value nan
I've also tried:
df.index=["CO ref","CO tus","CO raai"]
This changes the index correctly but the other columns do not switch so it messes up the dataframe.
Also:
df["sample"].index=["CO ref","CO tus","CO raai"]
But this does nothing.
How can I get this to work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…