how to sort a dataframe in python by one of the columns code example
Example 1: python sort dataframe by one column
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)
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)