1

I am getting an error while loading a file using Pandas Dataframe's to_sql method on an Informix Database. I am able to connect to the Informix database and execute the select query using the read_sql_query method like so:

df = pd.read_sql_query(query,con)

But the code below is throwing an error, and I can't figure out why:

con = pyodbc.connect(constr, autocommit=True) 
file ='/home/webload/rajesh.txt' 
df = pd.read_csv(file, sep="\t") 
pd.DataFrame.to_sql(name='customers', schema='informix', con=con, if_exists='append', index=False )

This is the error I'm receiving:

Traceback (most recent call last):
  File "connect1.py", line 42, in <module>
    pd.DataFrame.to_sql(name='customers', schema='informix',con=con, if_exists='append', index=False  )
TypeError: to_sql() missing 1 required positional argument: 'self'
IronFlare
  • 2,287
  • 2
  • 17
  • 27
Rajesh
  • 65
  • 6
  • 1
    The `to_sql` method is intended to be invoked on an existing `DataFrame` object, so `pd.DataFrame.to_sql` makes no sense. You really want to do `df.to_sql(...)` so pandas knows which DataFrame you want to upload. – Gord Thompson Jul 17 '19 at 01:07
  • @gordthompson Getting this error now: My database is Informix 'error' Traceback (most recent call last): File "/home/webload/anaconda3/lib/python3.7/site-packages/pandas/io/sql.py", line 1431, in execute cur.execute(*args) pyodbc.ProgrammingError: ('42S02', '[42S02] [Informix][Informix ODBC Driver][Informix]The specified table (sqlite_master) is not in the database. (-206) (SQLPrepare)') – Rajesh Jul 17 '19 at 02:46
  • @gordthompson I think ** to_sql** cannot be used for Informix. Is there a way to load into informix DB i – Rajesh Jul 17 '19 at 02:48

0 Answers0