Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
>>> import pandas
>>> pdf = pandas.DataFrame({"yield": [1, 2]})
>>> pdf
yield
0 1
1 2
>>> item = next(pdf.itertuples())
>>> item
Pandas(Index=0, _1=1)
Issue Description
The column named "yield" is renamed in itertuples
.
Expected Behavior
The column name remains unchanged.
Installed Versions
Comment From: mroeschke
This is as intended as the namedtuples are generated with rename=True
: https://docs.python.org/3/library/collections.html#collections.namedtuple
And this is tested in test_itertuples
This could be better documented
Comment From: mroeschke
Oh actually this is documented in the docstring
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.itertuples.html
The column names will be renamed to positional names if they are invalid Python identifiers, repeated, or start with an underscore.
Therefore closing
Comment From: snowman2
Thanks :+1:
Comment From: snowman2
Might not be bad to add a reference to this: https://realpython.com/python-keywords/
Comment From: snowman2
Or at least this: https://docs.python.org/3/library/keyword.html