Planet Python 中文 关注 LernerPython 博客,作者 Reuven Lerner:使用 dt 访问器对 datetime 部分进行 Pandas groupby 如果您的 Python Pandas 数据框包含 datetime 列,您可以通过"dt"访问器对该列的某一部分进行分组。例如,获取每天每个小时的平均行程距离:df.groupby(df['tpep_pickup_datetime'].dt.hour)['trip_distance'].mean() LernerPython blog, from Reuven Lerner: Pandas groupby on datetime parts with the dt accessor lernerpython.com Planet Python 中文 RSS thenote.app