Sorting pandas dataframe by column index instead of column name
Solution 1:
sort_values
is not an indexer but a method. You use it with []
instead of ()
but it doesn't seem to be the problem.
If you want to sort your dataframe by the second column whatever the name, use:
>>> df.sort_values(df.columns[1])
name score
1 Joe 3
0 Mary 10
2 Jessie 13