itertuples() | teradataml | Teradata - itertuples() Method - 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 itertuples() method to iterate over teradataml DataFrame rows as namedtuples.

This method returns iterator, an object to iterate over namedtuples for each row in the DataFrame.

Optional Parameters

name
Specifies the name of the returned namedtuples.

When set to None, the method returns the row in a list instead of namedtuple.

The default value is 'Row'.

num_rows
Specifies the number of rows to retrieve from the DataFrame.

When set to None, the method retrieves all the records. This is the default value.

Example 1: Retrieve all records from a teradataml DataFrame

>>> df = DataFrame("titanic")
>>> rows = df.itertuples()
>>> next(rows)
Row(passenger=78, survived=0, pclass=3, name='Moutal Mr. Rahamin Haim', gender='male', age=None, sibsp=0, parch=0, ticket='374746', fare=8.05, cabin=None, embarked='S')
>>> next(rows)
Row(passenger=93, survived=0, pclass=1, name='Chaffee Mr. Herbert Fuller', gender='male', age=46, sibsp=1, parch=0, ticket='W.E.P. 5734', fare=61.175, cabin='E31', embarked='S')
>>> next(rows)
Row(passenger=5, survived=0, pclass=3, name='Allen Mr. William Henry', gender='male', age=35, sibsp=0, parch=0, ticket='373450', fare=8.05, cabin=None, embarked='S')

Example 2: Retrieve the first 20 records from a teradataml DataFrame in a list, when DataFrame is ordered

This example retrieves the first 20 records from a teradataml DataFrame in a list, when the DataFrame is ordered by column "passenger".

>>> df = DataFrame("titanic")
>>> rows = df.sort("passenger").itertuples(name=None, num_rows=20)
>>> next(rows)
[1, 0, 3, 'Braund, Mr. Owen Harris', 'male', 22, 1, 0, 'A/5 21171', 7.25, None, 'S']
>>> next(rows)
[2, 1, 1, 'Cumings, Mrs. John Bradley (Florence Briggs Thayer)', 'female', 38, 1, 0, 'PC 17599', 71.2833, 'C85', 'C']
>>> next(rows)
[3, 1, 3, 'Heikkinen, Miss. Laina', 'female', 26, 0, 0, 'STON/O2. 3101282', 7.925, None, 'S']