我有一个合并的数据帧,如下所示:>>> merged_df.dtypes
Jurisdiction object
AdjustedVolume float64
EffectiveStartDate datetime64[ns]
VintageYear int64
ProductType object
Rate float32
Obligation float32
Demand float64
Cost float64
dtype: object
下面的groupby语句按辖区/年份返回正确的调整后的体积值:
^{pr2}$
包括产品类型时:>>> merged_df.groupby(['Jurisdiction', 'VintageYear','ProductType'])['AdjustedVolume'].sum()
如果辖区仅包含一个ProductType,则按年调整的卷是正确的,但对于具有两个或多个ProductType的任何辖区,调整的卷将被拆分,以使它们总和为正确的值。我希望每一行都有调整后的总量,但不清楚为什么要分开。在
示例:>>> merged_df.groupby(['Jurisdiction', 'VintageYear'])['AdjustedVolume'].sum()
Jurisdiction VintageYear AdjustedVolume
CA 2017 3.529964e+05
>>> merged_df.group