Note
Pandas (43) 본문
728x90
How to use apply function on existing columns with global variables as additional arguments?
# Input
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/Cars93_miss.csv')
# Solution
d = {'Min.Price': np.nanmean, 'Max.Price': np.nanmedian}
df[['Min.Price', 'Max.Price']] = df[['Min.Price', 'Max.Price']].apply(lambda x, d: x.fillna(d[x.name](x)), args=(d, ))
'Pandas' 카테고리의 다른 글
Pandas (45) (0) | 2022.09.11 |
---|---|
Pandas (44) (0) | 2022.09.10 |
Pandas (42) (0) | 2022.09.06 |
Pandas (41) (0) | 2022.09.04 |
Pandas (40) (0) | 2022.09.03 |
Comments