I have a dataframe of 2000 rows and 500 columns. I want to sort every column in ascending order. The columns don't have names they're just numbered 0-500.
Random data:
df = pandas.DataFrame(np.random.randint(0,100,size=(2000, 500)), columns=range(500))
Using
df.sort_values(by=0,axis=0)
sorts the 0th column, as expected. But then using df.sort_values(by=1,axis=0)
sorts the 1st column but shuffles the 0th column again. In other words, I want
index 0 1 2
1 5 5 5
2 6 7 5
3 7 9 8
But I can only ever get one column sorted at a time. I've tried df.sort_values(by=df.columns[0:524],axis=0)
but that throws a key error.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…