how to sort a dataframe in python by one of the columns code example

Example 1: python sort dataframe by one column

#following is example of sorting by the column "2" in descending order
final_df = df.sort_values(by=['2'], ascending=False)

Example 2: sort by dataframe

DataFrame.sort_values(self, by, axis=0, ascending=True,
                      inplace=False, kind='quicksort',
                      na_position='last',
                      ignore_index=False)

# Example
df.sort_values(by=['ColToSortBy'])

Example 3: dataframe, sort by columns

final_df = df.sort_values(by=['2'], ascending=False)

Example 4: 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)