I have the following (subset of a) Pandas dataframe that I am trying to upload to a MySQL database:
Here are details of the data using the info() function:
For added context, I previously converted both the tourn_date
and date
column to a datetime format using this code:
pd.to_datetime(all_data['tourn_date']).dt.date
Finally, here is the code that I'm using to import the data into the MySQL database:
for index, row in all_data.iterrows():
inserts = [row.tourn_id, row.year, row.round_num, row.tourn_date, row.date]
cursor.execute("""INSERT INTO AllPlayerStats
(TourneyID, Year, RoundNum, TourneyDate, TDate)
values(%s,%s,%s,%s,%s)""", inserts)
db.commit()
cursor.close()
However, when I run this, some of the dates (like the ones shown above), are appearing as NULL in the database (see below) despite other tournaments working just fine and the format of the TourneyDate
and Date
columns in the database being of date type. In some instances, the tourn_date
uploads correctly but the date
doesn't.
Is there a way to troubleshoot this and understand why this is occurring? I'm very confused as to what's going on here.
source https://stackoverflow.com/questions/72322609/dates-not-importing-to-sql-database-correctly-from-python
Comments
Post a Comment