-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.pivot(index=None) raises KeyError #52436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
DataFrame.pivot(index=None) seems to have changed behavior: pandas-dev/pandas#52436 Remove index=None so that it works across pandas versions.
DataFrame.pivot(index=None) seems to have changed behavior: pandas-dev/pandas#52436 Remove index=None so that it works across pandas versions.
Thanks @douglas-raillard-arm for the report This was caused by #48293 cc @phofl https://www.kaggle.com/code/marcogorelli/pandas-regression-example?scriptVersionId=124667072 |
Looks like df.pivot(columns='a', values='b') gives you your expected output, so maybe the docs just need to be updated to say "Column to use to make new frame’s index. If not given, uses existing index." |
I‘d say that this behaves as intended and needs a doc update |
take |
Hi Just to confirm we have to change the doc here if I'm not wrong can anyone help me here? I would like to contribute. Line 8677 in 3ce07cb
Thanks! |
yup |
Thanks, Marco for confirming 👍 |
Please also make sure to include it in the breaking change list on pandas 2.0.0: |
I think it's already written here Bug Fixes / reshaping or should I put |
I see how it is considered a bug fix but I think for the vast majority of people using strings as column names that will be a breaking change where the working default value has changed from None to no_default |
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
DataFrame.pivot() documentation states:
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.pivot.html
In pandas 1.5, index=None provides the expected result. In pandas 2.0.0, it raises a KeyError exception.
Expected Behavior
index=None should use the existing index as per documentation, or documentation should be modified and 2.0.0 breaking changes list updated to add that new behavior.
Installed Versions
pandas : 2.0.0
numpy : 1.24.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.6.1
pip : 23.0.1
Cython : None
pytest : 7.2.2
hypothesis : None
sphinx : 6.1.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.12.0
pandas_datareader: None
bs4 : 4.12.0
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: