How to Import Data into Teradata via Python?

DigNo Ape
2 min readAug 16, 2020

You will have to manipulate the data resides in multiple platforms when you do the data analysis, machine learning, reporting, etc. We are going to discuss how to leverage Python to upload the data in MS Excel and MS Access into Teradata.

Before we jump into the main topic, you need to have a file udaExec.ini stored in the same folder of py code and this file include your connection credential. Please ensure your name of ODBC setup is “Teradata”.

# Application Configuration
[CONFIG]
appName=CSVtry
version=1.0
logConsole=False
dataSourceName=Teradata

# Default Data Source Configuration
[DEFAULT]
method=odbc
charset=UTF8

# Data Source Definition
[Teradata]
dsn=Teradata
username= informula
password= passcode

MS Excel into Teradata

  • Required package: teradata/ pandas
  • Key Parts:
  1. Define path of Excel
  2. Read the data of the defined path
  3. Define connection of Teradata
  4. Delete the content of target table in Teradata
  5. Insert data into target table in Teradata
  • Full Py code
import teradata
import pandas as pd
path = "‪C:/Excel.xlsx"
file = pd.ExcelFile(path)
for name in file.sheet_names:
if 'Sheet1' in name:
sh_name = name
df = pd.read_excel(file, sheet_name = sh_name)
df = df[['Column1']].fillna('0')
udaExec = teradata.UdaExec(appName='${appName}'…

--

--