Skip to content

BUG: convert nan to None before insert data into mysql #4200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from pandas.core.datetools import format as date_format
from pandas.core.api import DataFrame, isnull
from pandas import notnull

#------------------------------------------------------------------------------
# Helper execution function
Expand Down Expand Up @@ -244,6 +245,8 @@ def _write_mysql(frame, table, names, cur):
wildcards = ','.join([r'%s'] * len(names))
insert_query = "INSERT INTO %s (%s) VALUES (%s)" % (
table, col_names, wildcards)
# convert NaN to None object
frame = frame.where(notnull(frame), None)
data = [tuple(x) for x in frame.values]
cur.executemany(insert_query, data)

Expand Down