How to fetch the data from Teradata using Python pandas

Teradata module for Python

Teradata module enables Python applications to connect to the Teradata Database, and interoperates with Teradata Database 12.0 and later releases. It can use either Teradata ODBC or REST API for Teradata database to connect and interact with Teradata.

Python pandas – Dataframe

Pandas is a package/library in python that used for data analysis.It makes importing, analyzing, and visualizing data much easier. Its key data structure is called the DataFrame. A Data frame is a two-dimensional data structure. It allow you to store and manipulate tabular data in rows and columns.

Import the required packages in Python

Lets install the teradata and pandas library in our machine using pip command as below.

Python program to fetch the data from Teradata table

The first line is imports the Teradata and pandas library that is used to fetch/store the data from the Teradata database. UdaExec is a framework that handles the configuration and logging the Teradata application. Since we mentioned the
logConsole=False , it will not log to the console so that our print statement is easier to read.

Once the Teradata connection established, we can run the select query to fetch the data from the Teradata database. Here we used pandas as pd that stores the result set of the SELECT query in dataframe.

Finally we just print the result of the query in console.

Changes required from your end before run this program

TDPROD – Modify your Teradata server address

USERNAME – Substitute Teradata user name

PASSWORD – Substitute Teradata password

Database and Table name – Give the valid database and Table name

Output

Fetch the data from the Teradata using python pandas

Recommended Articles