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

INSTALLED VERSIONS ------------------ commit : 8dab54d6573f7186ff0c3b6364d5e4dd635ff3e7 python : 3.9.15.final.0 python-bits : 64 OS : Linux OS-release : 5.15.0-58-generic Version : #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 1.5.2 numpy : 1.23.5 pytz : 2022.7.1 dateutil : 2.8.2 setuptools : 66.0.0 pip : 22.3.1 Cython : None pytest : 7.2.1 hypothesis : None sphinx : 5.3.0 blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : 2.9.3 jinja2 : 3.1.2 IPython : 8.8.0 pandas_datareader: None bs4 : 4.11.1 bottleneck : 1.3.5 brotli : fastparquet : None fsspec : 2022.11.0 gcsfs : None matplotlib : 3.6.2 numba : 0.56.4 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : 9.0.0 pyreadstat : None pyxlsb : None s3fs : 2022.11.0 scipy : 1.10.0 snappy : None sqlalchemy : 1.4.46 tables : None tabulate : 0.9.0 xarray : 2022.12.0 xlrd : None xlwt : None zstandard : None tzdata : 2022.7

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