Pandas groupby month and year

后端 未结 4 1415
闹比i
闹比i 2020-11-27 11:18

I have the following dataframe:

Date        abc    xyz
01-Jun-13   100    200
03-Jun-13   -20    50
15-Aug-13   40     -5
20-Jan-14   25     15
21-Feb-14   6         


        
4条回答
  •  青春惊慌失措
    2020-11-27 11:49

    Why not keep it simple?!

    GB=DF.groupby([(DF.index.year),(DF.index.month)]).sum()
    

    giving you,

    print(GB)
            abc  xyz
    2013 6   80  250
         8   40   -5
    2014 1   25   15
         2   60   80
    

    and then you can plot like asked using,

    GB.plot('abc','xyz',kind='scatter')
    

提交回复
热议问题