Pandas
Pandas (42)
Jun's N
2022. 9. 6. 18:32
How to replace missing values of multiple numeric columns with the mean?
# Input
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv')
# Solution
df_out = df[['Min.Price', 'Max.Price']] = df[['Min.Price', 'Max.Price']].apply(lambda x: x.fillna(x.mean()))
print(df_out.head())
# output
Min.Price Max.Price
0 12.900000 18.800000
1 29.200000 38.700000
2 25.900000 32.300000
3 17.118605 44.600000
4 17.118605 21.459091
728x90