我正在建立一些关于熊猫的报告,我想包括与整体价值的比较
假设我们有:
import pandas
data = {'puppy_name': ['Stanley', 'Doggo', 'Stanley', 'Doggo','Stanley', 'Doggo', 'Stanley', 'Doggo'],
'treats_earned': [25, 15, 20, 30, 20, 25, 20, 35],
'month': ['feb', 'feb', 'feb', 'feb','mar', 'mar', 'mar', 'mar']}
df = pandas.DataFrame(data)
我想展示的是:
pup / month / pup_avg / overall_month_avg
Stanley | feb | 22.5 | 22.5
Doggo | feb | 20 | 22.5
Stanley | mar | 20 | 25
Doggo | mar | 27.5 | 25
因此,对于一列,我们按['month','pup']分组/表示,对于另一列,我们按['month']分组/表示
我们需要
groupby
两次和map
相关问题 更多 >
编程相关推荐