1

I have a panda dataframe that has NaN values in it. Is there an easy to way to change all the NaNs to 0s? I don't want any other values to change.

1 Answer 1

1

Try the fillna function within pandas:

http://pandas.pydata.org/pandas-docs/dev/missing_data.html#filling-missing-values-fillna

 In [10]: df Out [10]: one two a 2.472772 1.135219 b NaN NaN c 0.863937 1.224622 d NaN 0.012517 In [11]: df2 = df.fillna(0) In [12]: df2 Out [12]: one two a 2.472772 1.135219 b 0.000000 0.000000 c 0.863937 1.224622 d 0.000000 0.012517 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.