pandas sort values by two columns code example

Example 1: sort by two columns in pandas

df.sort_values(['a', 'b'], ascending=[True, False])

Example 2: pandas sort values by multiple columns

df = df.sort_values(["b", "c"], ascending = (False, True))

Example 3: sort df by column

df.rename(columns={1:'month'},inplace=True)
df['month'] = pd.Categorical(df['month'],categories=['December','November','October','September','August','July','June','May','April','March','February','January'],ordered=True)
df = df.sort_values('month',ascending=False)