sorted = df.sort_values('column-to-sort-on', ascending=False)
#or
df.sort_values('name', inplace=True)
# Sorting Pandas Dataframe in Descending Order
# importing pandas library
import pandas as pd
# Initializing the nested list with Data set
age_list = [['Afghanistan', 1952, 8425333, 'Asia'],
['Australia', 1957, 9712569, 'Oceania'],
['Brazil', 1962, 76039390, 'Americas'],
['China', 1957, 637408000, 'Asia'],
['France', 1957, 44310863, 'Europe'],
['India', 1952, 3.72e+08, 'Asia'],
['United States', 1957, 171984000, 'Americas']]
# creating a pandas dataframe
df = pd.DataFrame(age_list, columns=['Country', 'Year',
'Population', 'Continent'])
# Sorting by column "Population"
df.sort_values(by=['Population'], ascending=False)
# Basic syntax:
import pandas as pd
df.sort_values(by=['col1'])
# Note, this does not sort in place unless you add inplace=True
# Note, add ascending=False if you want to sort in decreasing order
# Note, to sort by more than one column, add other column names to the
# list like by=['col1', 'col2']