DataFrame.from_dict() Function | Teradata Package for Python - DataFrame.from_dict Function - Teradata Package for Python

Teradata® Package for Python User Guide

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Teradata Package for Python
Release Number
20.00
Published
March 2025
ft:locale
en-US
ft:lastEdition
2025-12-05
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
Product Category
Teradata Vantage

Use the DataFrame.from_dict() function to create a DataFrame from a dictionary containing values as lists or numpy arrays.

Required Parameter

data
Specifies the Python dictionary of teradataml.

Optional Parameters

columns
Specifies the column names for the DataFrame.
persist
Specifies whether to persist the DataFrame.

Default value: false

Example setup

>>> from teradataml import DataFrame
>>> data_dict = {"name": ["Alice", "Bob", "Charlie"], "age": [25, 30, 28]}

Example 1: Create a teradataml DataFrame from a dictionary where keys are column names and values are lists of column data

>>> df = DataFrame.from_dict(data_dict)
>>> df
     name  age
0 Charlie   28
1     Bob   30
2   Alice   25

Example 2: Create a teradataml DataFrame from a dictionary where keys are column names and value are numpy arrays

>>> import numpy as np
>>> data_dict = {"col1": np.array([1, 2, 3]), "col2": np.array([4, 5, 6])}
>>> df = DataFrame.from_dict(data_dict)
>>> df
    col1 col2
0      3    6
1      2    5
2      1    4

Example 3: Persist the data from dictionary into a table which can be used across sessions

>>> df = DataFrame.from_dict(data_dict, persist=True)
>>> df
      name  age
0  Charlie   28
1      Bob   30
2    Alice   25

Get the database object name.

>>> df.db_object_name
'"ml__from_pandas_1761725700090504"'

Create the teradataml DataFrame using the database object name in different session.

>>> DataFrame('"ml__from_pandas_1761725700090504"')
      name  age
0  Charlie   28
1      Bob   30
2    Alice   25