Reputation: 164
I have a dataset like this:
A B
0 2 3
1 2 5
2 1 7
3 1 8
And I want to re-order it like this in a fast and efficient way:
A B
0 1 8
1 1 7
2 2 5
3 2 3
How can I achieve this efficiently?
Upvotes: 0
Views: 593
Reputation: 121
You could try the implementation given on this page.using the sort_values function. Assuming your data is stored in a data frame you can use `df.sort_values(by="B") For a better understanding go to the following link
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_values.html
Please check it out!
Upvotes: 0
Reputation: 97
According that your DataFrame is df, just use
df.sort_values(by='B')
Upvotes: 1