Note

Pandas (42) 본문

Pandas

Pandas (42)

알 수 없는 사용자 2022. 9. 6. 18:32
728x90

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

'Pandas' 카테고리의 다른 글

Pandas (44)  (0) 2022.09.10
Pandas (43)  (0) 2022.09.07
Pandas (41)  (0) 2022.09.04
Pandas (40)  (0) 2022.09.03
Pandas (39)  (0) 2022.08.31
Comments