Pandas: Combine TimeGrouper with another Groupby argument

前端 未结 2 1845
盖世英雄少女心
盖世英雄少女心 2021-01-11 23:21

I have the following DataFrame:

df = pd.DataFrame({
\'Branch\' : \'A A A A A B\'.split(),
\'Buyer\': \'Carl Mark Carl Joe Joe Carl\'.split(),
\'Quantity\': [         


        
2条回答
  •  时光取名叫无心
    2021-01-11 23:36

    You can now use a TimeGrouper with another column (as of IIRC pandas version 0.14):

    In [11]: df1 = df.set_index('Date')
    
    In [12]: g = df1.groupby([pd.TimeGrouper('20D'), 'Branch'])
    
    In [13]: g.sum()
    Out[13]:
                                Quantity
    Date                Branch
    2013-01-01 13:00:00 A              4
    2013-09-18 13:00:00 A             13
    2013-11-17 13:00:00 A              9
                        B              3
    

提交回复
热议问题