pandas 1.4.2

NotesParametersReturnsBackRef
itertuples(self, index: 'bool' = True, name: 'str | None' = 'Pandas') -> 'Iterable[tuple[Any, ...]]'

Notes

The column names will be renamed to positional names if they are invalid Python identifiers, repeated, or start with an underscore. On python versions < 3.7 regular tuples are returned for DataFrames with a large number of columns (>254).

Parameters

index : bool, default True

If True, return the index as the first element of the tuple.

name : str or None, default "Pandas"

The name of the returned namedtuples or None to return regular tuples.

Returns

iterator

An object to iterate over namedtuples for each row in the DataFrame with the first field possibly being the index and following fields being the column values.

Iterate over DataFrame rows as namedtuples.

See Also

DataFrame.items

Iterate over (column name, Series) pairs.

DataFrame.iterrows

Iterate over DataFrame rows as (index, Series) pairs.

Examples

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]},
...  index=['dog', 'hawk'])
... df num_legs num_wings dog 4 0 hawk 2 2
This example is valid syntax, but we were not able to check execution
>>> for row in df.itertuples():
...  print(row) ... Pandas(Index='dog', num_legs=4, num_wings=0) Pandas(Index='hawk', num_legs=2, num_wings=2)

By setting the :None:None:`index` parameter to False we can remove the index as the first element of the tuple:

This example is valid syntax, but we were not able to check execution
>>> for row in df.itertuples(index=False):
...  print(row) ... Pandas(num_legs=4, num_wings=0) Pandas(num_legs=2, num_wings=2)

With the :None:None:`name` parameter set we set a custom name for the yielded namedtuples:

This example is valid syntax, but we were not able to check execution
>>> for row in df.itertuples(name='Animal'):
...  print(row) ... Animal(Index='dog', num_legs=4, num_wings=0) Animal(Index='hawk', num_legs=2, num_wings=2)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.frame.DataFrame.iteritems pandas.core.frame.DataFrame.iterrows pandas.core.frame.DataFrame.items

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#1327
type: <class 'function'>
Commit: