Python Forum
Issue while inserting data into Teradata via python dataframe - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Issue while inserting data into Teradata via python dataframe (/thread-15983.html)



Issue while inserting data into Teradata via python dataframe - sandy - Feb-09-2019

Hi All
I am using below code to insert data into terdata table.
I am getting below error:
Output:
ProgrammingError: ('42000', "[42000] [Teradata][ODBC Teradata Driver][Teradata Database] Syntax error, expected something like '(' between the 'type' keyword and '='. (-3707) (SQLPrepare)") During handling of the above exception, another exception occurred:
for each in df:
    df1= each[each.TRAN_STMT_DESC.str.contains("SUPERBOOK")]
    df1['TRAN_STMT_DESC']='SUPERBOOK'
    #total=df1.groupby(['TRAN_STMT_DESC']).sum()
    print(df1.head())
Want to insert df1 data into table..

my code:
df1.to_sql(name='KLMD_SRM.PYTHON_LKP' ,con=conn_klm, if_exists='replace', index=False)

my connection settings:
td_userID = getpass.getpass('Enter User id')
td_password = getpass.getpass('Enter pwd')
conn_klm = pyodbc.connect('DSN=klm-LDAP;UID='+str(td_userID)+';PWD='+str(td_password))
del td_password, td_userID
conn_klm
conn_klm.autocommit = True 
curs = conn_klm.cursor()
HERE MY TABLE NAME :'PYTHON_LKP'
SCHEMA NAME : 'KLMD_SRM'

Please can one help me on this.

Thanks


RE: Issue while inserting data into Teradata via python dataframe - stullis - Feb-09-2019

My first impression is that this line:

df1= each[each.TRAN_STMT_DESC.str.contains("SUPERBOOK")]
is the problem. The "str" attribute could cause conflation between the attribute name and the string type. Still, it would be helpful to see the full traceback.


RE: Issue while inserting data into Teradata via python dataframe - sandy - Feb-10-2019

I am abel to print df1...

print(df1.head())
so there is data in df1.