“delivered_at”列是datetime,而started_week是对象列。我想知道,我如何使用groupby()函数将能够接收一周的聚合,以获得“deliver_at”列中值之间的平均天数差异?这样的事情:
started_week avg_delivered
2013-W03 7
答案 0 :(得分:2)
应该是
df.groupby('started_week').delivered_at.apply(lambda x: x.diff().mean())
started_week
2013-W03 7 days
Name: delivered_at, dtype: timedelta64[ns]