Skip to content
Advertisement

How to ignore NAN turning to String when using df.applymap(str)

I have to turn all the items in dataframe into string and i have tried as below,

df = df.applymap(str)

but it turns nan to string. How can i avoid nan to string here?

i tried as below, but not working.

df.where(~df.notna(),df.applymap(str))

Edit i tried df.applymap(str) but some reason i am getting boolean value of NA is ambiguous with my dataframe so i am opting only df.applymap(str)

Advertisement

Answer

You may try :

df = df.fillna('').astype(str)

Or you can have a look at this post.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement