【发布时间】:2022-01-07 12:29:51
【问题描述】:
我想通过两列子组的平均值填充 DataFrame 缺失的“年龄”值。
df.groupby(["col_x","col_y"])["Age"].mean()
上面的代码返回这些子组的均值:
col_X col_Y
X 1 35
2 29
3 22
Y 1 41
2 31
3 27
我感觉这可以通过使用 .map 函数来实现:
df.loc[df['Age'].isnull(),'Age'] = df[['col_X',"col_Y"]].map(something)
谁能帮我解决这个问题?
【问题讨论】:
标签: python pandas dataframe dictionary pandas-groupby