1>>> df.sort_values(by=['col1'], ascending = False)
2 col1 col2 col3
30 A 2 0
41 A 1 1
52 B 9 9
65 C 4 3
74 D 7 2
83 NaN 8 4
9
1>>> df.sort_values(by=['col1'])
2 col1 col2 col3
30 A 2 0
41 A 1 1
52 B 9 9
65 C 4 3
74 D 7 2
83 NaN 8 4
9
1df.rename(columns={1:'month'},inplace=True)
2df['month'] = pd.Categorical(df['month'],categories=['December','November','October','September','August','July','June','May','April','March','February','January'],ordered=True)
3df = df.sort_values('month',ascending=False)
1>>> df = pd.DataFrame({
2... 'col1': ['A', 'A', 'B', np.nan, 'D', 'C'],
3... 'col2': [2, 1, 9, 8, 7, 4],
4... 'col3': [0, 1, 9, 4, 2, 3],
5... 'col4': ['a', 'B', 'c', 'D', 'e', 'F']
6... })
7>>> df
8 col1 col2 col3 col4
90 A 2 0 a
101 A 1 1 B
112 B 9 9 c
123 NaN 8 4 D
134 D 7 2 e
145 C 4 3 F
15
16
17df.sort_values(by=['col1'])
18 col1 col2 col3 col4
190 A 2 0 a
201 A 1 1 B
212 B 9 9 c
225 C 4 3 F
234 D 7 2 e
243 NaN 8 4 D