You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
df2.A raises AttributeError: 'DataFrame' object has no attribute 'A' even though df2 has a column A. df2['A'] works as expected.
When I leave out the dtype="string" of the creation of df1, it works.
When I change the first argument of the .set_axis above to df1.iloc[0].astype('object') it works.
So df2.A works if the column index is of dtype object, but not if it is of dtype string.
Expected Behavior
df2.A works regardless of the dtype of the column index.
The Reproducable Example works with Pandas 1.2.4, probably because there every index is of dtype object.
(I noticed the bug after upgrading from 1.2.4 to 1.4.1, when production scripts stopped working.)
Installed Versions
INSTALLED VERSIONS
commit : 06d2301
python : 3.10.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19042
machine : AMD64
...
Pandas version checks
I have checked that this issue has not already been reported.
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
Issue Description
df2.A
raisesAttributeError: 'DataFrame' object has no attribute 'A'
even though df2 has a column A.df2['A']
works as expected.When I leave out the
dtype="string"
of the creation of df1, it works.When I change the first argument of the
.set_axis
above todf1.iloc[0].astype('object')
it works.So
df2.A
works if the column index is of dtype object, but not if it is of dtype string.Expected Behavior
df2.A
works regardless of the dtype of the column index.The Reproducable Example works with Pandas 1.2.4, probably because there every index is of dtype object.
(I noticed the bug after upgrading from 1.2.4 to 1.4.1, when production scripts stopped working.)
Installed Versions
INSTALLED VERSIONS
commit : 06d2301
python : 3.10.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19042
machine : AMD64
...
pandas : 1.4.1
numpy : 1.22.2
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: