pandas II
Sorting DataFrames
Learn how to sort a pandas DataFrame by one or more columns using sort_values(), and how to control the sort direction with the ascending parameter.
Use sort_values() to sort a DataFrame by one or more columns. By default it sorts in ascending order.
Sort by a column in ascending order (lowest first):
Python
Output
What will be the output?
Python
Pass ascending=False to reverse the order:
Python
Output
What will be the output?
Python
Sort by multiple columns by passing a list. The second column is used to break ties:
Python
Output
What will be the output?
Python
What will be the output?
Python
What will be the output?
Python