# pandas.DataFrame.itertuples¶

DataFrame.itertuples(index=True, name='Pandas')[source]

Iterate over DataFrame rows as namedtuples.

Parameters
indexbool, default True

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

namestr 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.

DataFrame.iterrows

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

DataFrame.items

Iterate over (column name, Series) pairs.

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).

Examples

>>> 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
>>> 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 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)
...
Pandas(num_legs=4, num_wings=0)
Pandas(num_legs=2, num_wings=2)


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

>>> 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)
{"ft_lang_label":"__label__en","ft_lang_prob":0.52490723,"math_prob":0.88989025,"size":1486,"snap":"2023-14-2023-23","text_gpt3_token_len":408,"char_repetition_ratio":0.15317139,"word_repetition_ratio":0.04784689,"special_character_ratio":0.27725437,"punctuation_ratio":0.21262458,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9818299,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-21T05:27:56Z\",\"WARC-Record-ID\":\"<urn:uuid:c5430aab-f317-47af-98e5-ccd46c430b71>\",\"Content-Length\":\"33207\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:da6a91e0-0316-4cf8-ae48-062dd7f05d55>\",\"WARC-Concurrent-To\":\"<urn:uuid:cf3c4456-2051-4561-b779-eba2f51b4b27>\",\"WARC-IP-Address\":\"104.26.1.204\",\"WARC-Target-URI\":\"https://pandas.pydata.org/pandas-docs/version/1.1.2/reference/api/pandas.DataFrame.itertuples.html\",\"WARC-Payload-Digest\":\"sha1:576AOM2FY55TT44TOBDXJ75TKWQ25TRA\",\"WARC-Block-Digest\":\"sha1:4C6YCGDKMRYOGY2DJAR3EZRHJZP6VZHQ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296943625.81_warc_CC-MAIN-20230321033306-20230321063306-00670.warc.gz\"}"}