Managing nan when inserting a pandas DataFrame with sqlalchemy executemany

Solution 1:

The real problem is that dff.values create a typed matrix whom can't countained None values for int or float. But in reality the executemany can insert None values.

The fastest solution I've found is to correct the list of lists given to executemany instead of correcting the dataframe content before creating the list of lists.

My inserted data aren't dff.values.tolist() anymore but:

inserted_data = [
    [None if pd.isnull(value) else value for value in sublist] \
    for sublist in dff.values.tolist()]

mycursor.executemany(query_template, inserted_data )