DataFrame.itertuples(index: bool = True, name: Optional[str] = 'Eland') → Iterable[Tuple[Any, ...]]

Iterate over eland.DataFrame rows as namedtuples.


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.

See also


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


>>> df = ed.DataFrame('localhost:9200', 'flights', columns=['AvgTicketPrice', 'Cancelled']).head()
>>> df
   AvgTicketPrice  Cancelled
0      841.265642      False
1      882.982662      False
2      190.636904      False
3      181.694216       True
4      730.041778      False
[5 rows x 2 columns]
>>> for row in df.itertuples():
...     print(row)
Eland(Index='0', AvgTicketPrice=841.2656419677076, Cancelled=False)
Eland(Index='1', AvgTicketPrice=882.9826615595518, Cancelled=False)
Eland(Index='2', AvgTicketPrice=190.6369038508356, Cancelled=False)
Eland(Index='3', AvgTicketPrice=181.69421554118, Cancelled=True)
Eland(Index='4', AvgTicketPrice=730.041778346198, Cancelled=False)

By setting the index parameter to False we can remove the index as the first element of the tuple: >>> for row in df.itertuples(index=False): … print(row) Eland(AvgTicketPrice=841.2656419677076, Cancelled=False) Eland(AvgTicketPrice=882.9826615595518, Cancelled=False) Eland(AvgTicketPrice=190.6369038508356, Cancelled=False) Eland(AvgTicketPrice=181.69421554118, Cancelled=True) Eland(AvgTicketPrice=730.041778346198, Cancelled=False)

With the name parameter set we set a custom name for the yielded namedtuples: >>> for row in df.itertuples(name=’Flight’): … print(row) Flight(Index=’0’, AvgTicketPrice=841.2656419677076, Cancelled=False) Flight(Index=’1’, AvgTicketPrice=882.9826615595518, Cancelled=False) Flight(Index=’2’, AvgTicketPrice=190.6369038508356, Cancelled=False) Flight(Index=’3’, AvgTicketPrice=181.69421554118, Cancelled=True) Flight(Index=’4’, AvgTicketPrice=730.041778346198, Cancelled=False)