How to Replace NaN ...
 
Share:
Notifications
Clear all

How to Replace NaN with blank/empty string in Python Pandas?


myTechMint
(@mytechmint)
Member Moderator
Joined: 4 years ago
Posts: 52
Topic starter  

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

Quote
Topic Tags
myTechMint
(@mytechmint)
Member Moderator
Joined: 4 years ago
Posts: 52
Topic starter  

UseĀ 

df = df.fillna('')

or just

df.fillna('', inplace=True)

This will fill na's (e.g. NaN's) with ''.

If you want to fill a single column, you can use:

df.column1 = df.column1.fillna('')

One can use df['column1'] instead of df.column1.


ReplyQuote