LernerPython 博客,作者 Reuven Lern... 笔记

LernerPython 博客,作者 Reuven Lerner:Pandas groupby:使用多个函数对多列进行聚合

Python Pandas 是否支持多数据列和多方法?是的!df.groupby('passenger_count')[['trip_distance', 'total_amount']].agg(['mean', 'std'])上述代码返回一个数据框。其 4 列具有一个 2 级多索引,其中均值/标准差位于内层。
CdXz5zHNQW_SH2qLnYdGP.png