user14073111
user14073111

Reputation: 621

How to insert NaN value to MariaDB using python

I have a dataframe like this and i want to insert it to MariaDB database using python:

      col1      col2       col3     col4
0      A         21         21       92
1      B         62         54       62
2      C         63         98       41
3      D         64         97       NaN
4      E         76         NaN      NaN

when I try to insert it to MariaDB i get an error saying:

mariadb.DataError: Invalid parameter type at row 5, column 3

In my table in MariaDB I specified to accept NULL values

How do I correct this problem?

Upvotes: 0

Views: 279

Answers (1)

Avinash_cdns
Avinash_cdns

Reputation: 295

df.where(pd.notnull(df), None)

my pandas version is higher than 0.13: try this

             col1      col2       col3     col4
      0      A         21         21       92
      1      B         62         54       62
      2      C         63         98       41
      3      D         64         97       None
      4      E         76         None     None

Upvotes: 2

Related Questions