user1452759 user1452759 - 1 year ago 417
Python Question

Pandas Replace NaN with blank/empty string

I have a Pandas Dataframe as shown below:

1 2 3
0 a NaN read
1 b l unread
2 c NaN read

I want to remove the NaN values with an empty string so that it looks like so:

1 2 3
0 a "" read
1 b l unread
2 c "" read

Answer Source
import numpy as np
df1 = df.replace(np.nan,' ', regex=True)

This might help. It will replace all Nans with a blank space.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download