我有与时间戳和自定义组关联的表格数据(由col1,col2等描述)。例:
I would like to create time bins (like with resample function), average values WITHIN the same group, and THEN sum them up within the same time bin.
But if I write dataframe.resample("2D").sum()
, values will be direclty summed up over all the groups without first being averaged in the same group. Like this:
但是我需要的是在求和之前对属于同一组的值求平均值。在这种情况下,所需的输出将是:
I tried to apply groupby after resampling (e.g. dataframe.resample("2D").grouby("Group")
), but it raises a TypeError ("'TimeGrouper' object is not callable")
有什么办法可以解决这个问题?提前致谢。
I believe you can first aggregate
mean
and then useresample
: