Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

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

1 Answer

0 votes
by (41.4k points)

It will replace all NaNs with an empty string.

import numpy as np

df1 = df.replace(np.nan, '', regex=True)

If you wish to learn more about Data Science, visit the data science tutorial and data science course by Intellipaat.

Browse Categories

...