我的数据框如下所示。我正在尝试根据数据框中aggregate(sum)
存在的日期和组来计算我的金额列pandas
。我能够成功aggregate
的列。但是,我不确定如何传入fbprophet以根据分组日期和组预测未来值。下面是聚合的代码。注意:我是python初学者,请提供代码解释。
数据框
import pandas as pd
data = {'Date':['2017-01-01', '2017-01-01','2017-01-01','2017-01-01','2017-01-01','2017-01-01','2017-01-01','2017-01-01',
'2017-02-01', '2017-02-01','2017-02-01','2017-02-01','2017-02-01','2017-02-01','2017-02-01','2017-02-01'],'Group':['A','A','B','B','C','C','D','D','A','A','B','B','C','C','D','D'],
'Amount':['12.1','13.2','15.1','10.7','12.9','9.0','5.6','6.7','4.3','2.3','4.0','5.6','7.8','2.3','5.6','8.9']}
df = pd.DataFrame(data)
到目前为止尝试的代码:
grouped = df.groupby(['Group','Date'])[['Amount']].sum()