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. How can i do that?
I cannot use df.to_sql to write to DB, it is very slow. So I use pymsql. I convert the dataframe values as a tuple and form a sql insert statement. Hence i cannot have None, Nan, NAT etc. need to even clear it before writing to tuple.
self.sqlconn = pymssql.connect(server=self.server, user=self.username, password=self.password,database=self.database)
code for writing to sql db
cursor = self.sqlconn.cursor()
for i in sql_dataframe.values:
query = 'insert into ' + table_name + ' (' + ','.join(sql_dataframe.columns) + ') values ' + str(
tuple(i))