1

So basically I have a function that retrieves data from an API and produces a data series with columns (Data, Realtime Start, Value) I then have a program that inserts table named using values from my dictionary. I, however, cannot figure out how to upload the data series to these tables. I tried many ways and it either inputs values from random data series elements or hit me with an error: AttributeError: 'Timestamp' object has no attribute 'translate'

here is the code:

country_index = input('Country Code: ')

engine = create_engine('mysql+pymysql://user:pass@localhost:3306/{}'.format(country_index))
connection = engine.connect()


for lines in countryDict[country_index]:
    lines.splitlines()
    fredder = fred.get_series_all_releases(lines)


def Database_Table_Creator():

      for table in countryDict[country_index]:
          table.splitlines()

          queryCreateTable = """CREATE TABLE `{}`(
                                DATE int,
                                REALTIME_START int,
                                VALUE int
                                )""".format(table)

          connection.execute(queryCreateTable)

          fredder.to_sql(
                  name = '{}'.format(table),
                  con = connection,
                  index = False,
                  if_exists='append',
                  chunksize = 500)


      connection.close()


Database_Table_Creator()
Robex
  • 47
  • 3
  • 9
  • It would be helpful to see more of the error message to see which function call is causing it, I'm guessing to_sql. The issue seems to be that one or both of your fields, DATE and REALTIME_START are stored as a Pandas Timestamp objects. (https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Timestamp.html) and there is not a clear way for whichever function is failing to translate it to an int. You could try setting the column type to datetime64 or, if you want to stick with int, converting your date fields to unix time. Hope this helps. – Andrew McDowell Sep 20 '18 at 09:25
  • I have the same Issue. I keep getting "Python installation has no SSL support" after installing mysql through Anaconda. – alex Jan 15 '19 at 21:01

0 Answers0