0

I am trying to store data frame into mysql after converting it to dictionary

# a_two.fillna(0)
for data in a_two:
    fav_two = BankData(process_date=data.get('Process date'), description=data.get(
        'Description'), debit=data.get('Debit'), credit=data.get('Credit'), balance=data.get('Balance'), category=data.get('Categories'))
    db.session.add(fav_two)
    db.session.commit()

print("Bank data submitted")
return render_template("index.html")
Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
Jay Patel
  • 37
  • 10
  • 1
    Looks like you are passing a pandas `Timestamp` as an argument to your query, see https://github.com/PyMySQL/PyMySQL/issues/499 and https://stackoverflow.com/questions/46205532/numpy-float64-object-has-no-attribute-translate-inserting-value-to-mysql-in. The solution is to convert the arguments before passing them to the query, or in this case the ORM object. "Process date" sounds like a good candidate to check. – Ilja Everilä Mar 10 '20 at 06:40
  • 1
    ...If it indeed is a `pandas.Timestamp`, consider using [`to_pydatetime`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Timestamp.to_pydatetime.html#pandas.Timestamp.to_pydatetime) before passing it as an argument to `BankData`. Some other questions that seem related: https://stackoverflow.com/questions/43108164/python-to-mysql-timestamp-object-has-no-attribute-translate, https://stackoverflow.com/questions/46034756/inserting-timestamp-column-from-list-to-mysql-using-python. – Ilja Everilä Mar 10 '20 at 06:44
  • ```127.0.0.1 - - [10/Mar/2020 19:55:30] "POST /upload_two HTTP/1.1" 200 - datetime64[ns]``` – Jay Patel Mar 10 '20 at 09:02
  • data type is alright, still having same issue... – Jay Patel Mar 10 '20 at 09:03

0 Answers0