QuaPa77
@QuaPa77 (p q)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

fillnaがうまく動かないです

fillnaで変更できない

欠損値を消そうとしてもfillnaの前後で欠損値が消えません、原因を教えていただきたいです

発生している問題・エラー

print(df.loc[df.Title=='Mr.','Age'])
df.loc[df.Title=='Mr.','Age'].fillna(0,inplace=True)
print(df.loc[df.Title=='Mr.','Age'])

出力

0      22.0
4      35.0
5       NaN
6      54.0
12     20.0
       ... 
881    33.0
883    28.0
884    25.0
889    26.0
890    32.0
Name: Age, Length: 517, dtype: float64
0      22.0
4      35.0
5       NaN
6      54.0
12     20.0
       ... 
881    33.0
883    28.0
884    25.0
889    26.0
890    32.0
Name: Age, Length: 517, dtype: float64

5番のNaNが消えません...

0

2Answer

inplace引数を使わずに=で代入してください。

df.loc[df.Title=='Mr.', 'Age'] = df.loc[df.Title=='Mr.', 'Age'].fillna(0)
1Like

Your answer might help someone💌