Pandas数据框组月份

时间:2017-05-15 14:09:35

标签: python pandas grouping

在Python中我有一些.xls格式的降雨数据,从1991年到2015年(月)从1到12的列(降雨量)(年),我想按月而不是数年对数据进行分组。 以下是数据的预览:

  Rainfall (mm)     Year   Month   
         118.969    1991       1            
         202.265    1991       2            
         255.006    1991       3            
         170.505    1991       4            
         223.541    1991       5

我想谈谈这个问题:

      Rainfall (mm)     Year   Month   
             -          1991       1            
             -          1992       1            
             -          1993       1            
             -          1994       1            
             -          1995       1

1 个答案:

答案 0 :(得分:0)

IIUC,您希望使用`sort_values'

按年对数据进行排序
df = df.sort_values(by=['Month','Year'])
相关问题