为调查中的每个组乘以 groupby 元素

Multplying groupby elements for each group in survey

我正在处理 Stack Overflow 2019 调查数据。 here is Survey 2019 data.

该数据中有很多列。

我想进行这个计算---> "Sum of Age1stCode" / "Number of people who are related years old"。

Age1stCode 是调查中的一个列,说明了第一年的编码。年龄是"age years old".

的一列

我根据"Age"建了一个群。

我只想将每个相反的数字相乘,然后求和。例如,对于 11 岁 = (6x3)+(7x3)+ (9x2)+......(8x1)。我想为每个年龄段的人做这个。所以最后,我想获得像我附加的文件那样的输出“Age 11.0 ----> 326(例如,它只是随机的),Age 12.0 ---> 468)

我的目标是计算这个 ---> 每个年龄组的 Age1stCode 总和。

here is the output that I want to work with. Attached File.

df_grouped = df.groupby('Age').agg({'Age1stCode': 'sum'}).reset_index()
new_col = df_grouped['Age1stCode'] / df_grouped['Age']