【发布时间】:2019-01-05 07:58:15
【问题描述】:
我有这个数据
import numpy as np
import pandas as pd
group = {'gender': ['male', 'female', 'female', 'male', 'female', 'male', 'male'],
'height': [175, 168, np.nan, 170, 167, np.nan, 190],
}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
df = pd.DataFrame(group, index=labels)
df2 = df.groupby('gender')['height'].mean()
我想用 df2 的平均值填充 nan
【问题讨论】:
标签: python pandas numpy dataframe pandas-groupby