I have a dataframe of 2000 rows and 500 columns. I want to sort each column in ascending order. Columns have no names; they are simply numbered 0-500.
Random data:
df = pandas.DataFrame(np.random.randint(0,100,size=(2000, 500)), columns=range(500))
Usage
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 again shuffles the 0th column. 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 get one column sorted at a time. I tried df.sort_values(by=df.columns[0:524],axis=0), but this causes a key error.
source
share