Teradata Package for Python Function Reference on VantageCloud Lake - from_records - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference on VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Package for Python
Release Number
20.00.00.08
Published
November 2025
ft:locale
en-US
ft:lastEdition
2025-12-05
dita:id
TeradataPython_FxRef_Lake_2000
Product Category
Teradata Vantage
teradataml.dataframe.dataframe.DataFrame.from_records = from_records(data, columns=None, **kwargs) method of builtins.type instance
DESCRIPTION:
    Create a DataFrame from a list of lists/tuples/dictionaries/numpy arrays.
 
PARAMETERS:
    data:
        Required Argument.
        Specifies the iterator of data or the list of lists/tuples/dictionaries/numpy arrays to 
        be converted to teradataml DataFrame.
        Note:
            * Nested lists or tuples or dictionaries are not supported.
        Types: Iterator, list
 
    columns:
        Optional Argument.
        Specifies the column names for the DataFrame.
        Note:
            * If the data is a list of lists/tuples/numpy arrays and this argument
              is not specified, column names will be auto-generated as 'col_0', 'col_1', etc.
        Types: str OR list of str
 
    kwargs:
        exclude:
            Optional Argument.
            Specifies the columns to be excluded from the DataFrame.
            Types: list OR tuple
 
        coerce_float:
            Optional Argument.
            Specifies whether to convert values of non-string, non-numeric objects (like decimal.Decimal) 
            to floating point, useful for SQL result sets.
            Default Value: True
            Types: bool
 
        nrows:
            Optional Argument.
            Specifies the number of rows to be read from the data if the data is iterator.
            Types: int
 
RETURNS:
    teradataml DataFrame
 
RAISES:
    TeradataMlException
 
EXAMPLES:
    >>> from teradataml import DataFrame
 
    # Example 1: Create a teradataml DataFrame from a list of lists.
    >>> df = DataFrame.from_records([['Alice', 1], ['Bob', 2]], columns=['name', 'age'])
    >>> df
        name  age
    0    Bob    2
    1  Alice    1
 
    # Example 2: Create a teradataml DataFrame from a list of tuples.
    >>> df = DataFrame.from_records([('Alice', 1), ('Bob', 3)], columns=['name', 'age'])
    >>> df
        name  age 
    0    Bob    3
    1  Alice    1
 
    # Example 3: Create a teradataml DataFrame from a list of dictionaries.
    >>> df = DataFrame.from_records([{'name': 'Alice', 'age': 4}, {'name': 'Bob', 'age': 2}])
    >>> df
        name  age 
    0    Bob    2
    1  Alice    4
 
    # Example 4: Create a teradataml DataFrame from a list where columns
    #            are not explicitly defined.
    >>> df = DataFrame.from_records([['Alice', 1], ['Bob', 2]])
    >>> df
       col_0  col_1 
    0    Bob      2
    1  Alice      1
 
    # Example 5: Create a teradataml DataFrame from a list by excluding 'grade' column.
    >>> df = DataFrame.from_records([['Alice', 1, 'A'], ['Bob', 2, 'B']], 
    ...                               columns=['name', 'age', 'grade'], 
    ...                               exclude=['grade'])
    >>> df
        name  age 
    0    Bob    2
    1  Alice    1
 
    # Example 6: Create a teradataml DataFrame from a list of lists
    #            with "coerce_float" set to False.
    >>> df = DataFrame.from_records([[1, Decimal('2.5')], [3, Decimal('4.0')]],
    ...                              columns=['col1', 'col2'], coerce_float=False)
    >>> df
        col1  col2 
    0      3   4.0
    1      1   2.5
    >>> df.tdtypes
    col1                                          BIGINT()
    col2           VARCHAR(length=1024, charset='UNICODE')
 
    # Example 7: Create a teradataml DataFrame from a list of lists
    #            with "coerce_float" set to True.
    >>> from decimal import Decimal
    >>> df = DataFrame.from_records([[1, Decimal('2.5')], [3, Decimal('4.0')]],
    ...                              columns=['col1', 'col2'], coerce_float=True)
    >>> df
       col1  col2 
    0     3   4.0
    1     1   2.5
    >>> df.tdtypes
    col1           BIGINT()
    col2            FLOAT()
 
    # Example 8: Create a teradataml DataFrame from an iterator with "nrows" set to 2.
    >>> def data_gen():
    ...     yield ['Alice', 1]
    ...     yield ['Bob', 2]
    ...     yield ['Charlie', 3]
    >>> df = DataFrame.from_records(data_gen(), columns=['name', 'age'], nrows=2)
    >>> df
        name  age 
    0    Bob    2
    1  Alice    1