我只想通过ID和给定的值求和,这取决于一系列的日期
我试过这个:
days=(360)
import datetime
import pandas as pd
group = None
df=pd.read_excel(r'C:\Users\xxxx\Desktop\xxxxx.xlsx')
for i in days:
D = ((datetime.datetime.now()-datetime.timedelta(days=i)))
B = D <= df['DATE']
group = df.groupby('ID')['VALUE'].filter(lambda x: B ).sum()
测向:
DATE ID VALUE
2019-01-01 1 10
2019-02-01 2 15
2019-03-01 1 12
但是有一个错误
TypeError: the filter must return a boolean result
即使是B型也是布尔
我需要的结果是:
ID Value
1 22
2 15
我相信您需要在} 进行过滤:
groupby
之前通过^{或:
相关问题 更多 >
编程相关推荐