0

I have a numeric variable (stored as object) where one single value is "NA", how could I replace this with a zero? Thanks!

df['Var_A'].loc[28:35]

28     2.99
29     7.81
30     "NA"
31    13.55
32     8.25
33      6.2
34     8.77
35     2.67
Name: Var_A, dtype: object
4
  • 2
    df['Var_A'].replace("NA", 0) Commented Jan 29, 2019 at 11:26
  • Use df['Var_A'].replace("NA", 0).astype(float) or pd.to_numeric(df['Var_A'], errors='coerce') Commented Jan 29, 2019 at 11:27
  • thanks guys, I tried both but the "NA" is still there Commented Jan 29, 2019 at 11:45
  • you missed the assignment part. Use like this. df['Var_A'] = df['Var_A'].replace("NA", 0) Commented Jan 29, 2019 at 12:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.