【发布时间】:2017-10-17 13:16:12
【问题描述】:
我有一个数据框,假设有 2 列:日期和双精度数
2017-05-01 2.5
2017-05-02 3.5
... ...
2017-05-17 0.2
2017-05-18 2.5
现在我想做一个 groupby 并用 x 行求和。因此,即返回 6 行:
2017-05-06 15.6
2017-05-12 13.4
2017-05-18 18.0
是否有一个干净的解决方案可以做到这一点,而无需通过类似这样的 for 循环运行它:
temp = pd.DataFrame()
j = 0
for i in range(0,len(df.index),6):
temp[df.ix[i]['date']] = df.ix[i:i+6]['value'].sum()
【问题讨论】: