atm atm - 3 years ago 340
Python Question

Read Teradata query into Pandas

Has anyone found a way to read a Teradata query into a Pandas dataframe? It looks like SQLAlchemy does not have a Teradata dialect.

Answer Source

I did it using read_sql . Below id the code snip :

def dqm() :
    conn_rw = create_connection()
    dataframes = []
    srcfile = open('srcqueries.sql', 'rU').read()
    querylist = srcfile.split(';')
    for query in querylist :
        dataframes.append(pd.read_sql(query, conn_rw))
    return dataframes,querylist

You can create connection as below :

    def create_connection():
        conn = pyodbc.connect("DRIVER=Teradata;DBCNAME=tddb;UID=uid;PWD=pwd;QUIETMODE=YES", autocommit=True,unicode_results=True)
        return conn

You can check complete code here : GitHub Link Let me know if this answers your query .

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download