我想在 pandas Grouper 中使用最后一个日期作为引用,而不是像代码那样使用第一个日期。
接下来就是这个想法。
我的 df 是
date value c1 c2
2019-03-06 500000.0 1 1
2019-03-16 500000.0 2 2
2019-04-06 300000.0 1 1
当我使用时:
df.groupby(pd.Grouper(key='date',freq='30D')):
2019-03-06 1000000.0 3
2019-04-05 300000.0 1
但我想要
2019-03-06 500000.0 1
2019-04-05 800000.0 3
最佳答案
我认为应该是 31 天
df.groupby(pd.Grouper(key='date',freq='31D',closed='right', label='right')).sum()
Out[325]:
value c1 c2
date
2019-03-06 500000.0 1 1
2019-04-06 800000.0 3 3
关于python - 如何使用 Grouper 进行分组,但我想使用最近的日期作为频率的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56603786/