I have a Pandas Dataframe as shown below:
JavaScript
x
5
1
1 2 3
2
0 a NaN read
3
1 b l unread
4
2 c NaN read
5
I want to remove the NaN values with an empty string so that it looks like so:
JavaScript
1
5
1
1 2 3
2
0 a "" read
3
1 b l unread
4
2 c "" read
5
Advertisement
Answer
JavaScript
1
3
1
import numpy as np
2
df1 = df.replace(np.nan, '', regex=True)
3
This might help. It will replace all NaNs with an empty string.