Home > Software engineering >  Replace None in pandas data frame with Null
Replace None in pandas data frame with Null

Time:06-29

I have a pandas dataframe and i am getting None for many values. I need to write it to SQL server DB and want to update it with Null. Any pointers on how to do that.

CodePudding user response:

try replacing None with explicit NULLs

df['col'] = df['col'].fillna('NULL')

CodePudding user response:

Just do:

df = df.fillna(value = None) # replace <na> and NaN to None
# Also possible:
df = df.replace({np.na: None}) 
df = df.replace({np.nan: None})

None will be Null in your DMS.

For further information:

DataFrame.Fillna Doc

Null in Python

pd.NA vs np.nan for pandas

  • Related