example = pd.DataFrame({'Amount':[74.,235.,175.,100.,115.,245.,180.,90.,88.,129.,273.,300.],'Category':['Transportation','Grocery','Household','Entertainment','Transportation','Grocery','Household','Entertainment','Transportation','Grocery','Household','Entertainment'],'Month':['January','January','January','January','February','February','February','February','Marth','Marth','Marth','Marth']})
example
Amount
Category
Month
0
74.0
Transportation
January
1
235.0
Grocery
January
2
175.0
Household
January
3
100.0
Entertainment
January
4
115.0
Transportation
February
5
245.0
Grocery
February
6
180.0
Household
February
7
90.0
Entertainment
February
8
88.0
Transportation
Marth
9
129.0
Grocery
Marth
10
273.0
Household
Marth
11
300.0
Entertainment
Marth
1. 排序操作
example.sort_values(by=['Month','Amount'], ascending=[True,False])# by 指定按照哪些属性排序 Month放在第一个 先把Month 按照升序排序,再对Amount降序排序
Amount
Category
Month
5
245.0
Grocery
February
6
180.0
Household
February
4
115.0
Transportation
February
7
90.0
Entertainment
February
1
235.0
Grocery
January
2
175.0
Household
January
3
100.0
Entertainment
January
0
74.0
Transportation
January
11
300.0
Entertainment
Marth
10
273.0
Household
Marth
9
129.0
Grocery
Marth
8
88.0
Transportation
Marth
data = pd.DataFrame({'k1':[1,2,3,5,5,4,6,2,2],'k2':[12,8,11,4,4,52,30,18,18]})
data