Skip to content
Advertisement

Replacing None with a list within a dataframe

I have the below dataframe which comes from a JSON


JavaScript

trying to format ready for db insertion, i am splitting using .tolist() but getting error for None entries.

tried fillna and replace to insert a dummy list i.e. [0,0,0] but will only let me replace with a string. Any suggestions welcome.

this works

#df_split_batl = df_split_batl.fillna(‘xx’) #df_split_batl = df_split_batl.replace(‘xx’,’yy’)

but these dont

#df_split_batl = df_split_batl.fillna([0,0,0])

#df_split_batl = df_split_batl.fillna(‘xx’)

#df_split_batl = df_split_batl.replace(‘xx’,[0,0,0])

Advertisement

Answer

Check the following link, it might be helpful for your case: Replace NaN with empty list in a pandas dataframe

Instead of replacing it with an empty list, you’ll replace it with a list containing elements.

RGS20 :)

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