Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.

Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame({'num_legs': [4, 2], 'num_wings': [0, 2]},
                  index=['fox', 'eagle'])
df
Out[2]:
num_legs num_wings
fox 4 0
eagle 2 2

Pandas: DataFrame - intertuples.

In [3]:
for row in df.itertuples():
    print(row)
Pandas(Index='fox', num_legs=4, num_wings=0)
Pandas(Index='eagle', num_legs=2, num_wings=2)

Pandas: DataFrame - intertuples print row.

In [4]:
for row in df.itertuples(index=False):
    print(row)
Pandas(num_legs=4, num_wings=0)
Pandas(num_legs=2, num_wings=2)

Pandas: DataFrame - intertuples, index false, print row.

With the name parameter set we set a custom name for the yielded named tuples:

In [5]:
for row in df.itertuples(name='Animal'):
    print(row)
Animal(Index='fox', num_legs=4, num_wings=0)
Animal(Index='eagle', num_legs=2, num_wings=2)

Pandas: DataFrame - intertuples, With the parameter set we set a custom  name for the yielded named tuples.