I am trying to put the current timestamp into the data frame then save the records to the MySQL database. Here is my table design: Table Design
Here is my code `
df = pd.read_csv(uploaded_file, keep_default_na=False)`
df= df.where(pd.notnull(df), None)
column_name = df.columns
current_time = datetime.utcnow()
date_object = datetime.strftime(current_time, '%Y-%m-%d %H:%M:%S:%f')
df.loc[df['wDate']== '',df['wDate']] = date_object
df.loc[df['mDate']== '',df['wDate']] = date_object
try:
for i,row in df.iterrows():
sql = "INSERT INTO Build VALUES \
(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
print (tuple(row))
curs.execute(sql, tuple(row))
#st.write("Record inserted", i)
conn.commit()
except Exception as e:
st.write ('ERROR! DB.', e)
else:
st.write('successfully uploaded..')
However, when I try to print the data in the output just to see how the row would look like, they appear like this:
('b1', 'a101', 'fp1', 202, 1109, 'f1', '', 'p1', 'p2', 'p4', '', 'b1', 'b1', 'b12', '', 's1', '', '', 'c1', '', '', '', 'nita', '2021-12-10 11:56:10:778920', '2021-12-10 11:56:10:778920')
It seems like the current dates that I want to input went to two additional columns which cause the "TypeError: not all arguments converted during string formatting"
I am not sure what went wrong.