BUG: Wrong error message is raised when columns=None in df.pivot · Issue #30924 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
From docstring, index
and values
can be optional in df.pivot, but columns
is not
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.pivot.html
index : string or object, optional
Column to use to make new frame’s index. If None, uses existing index.
columns : string or object
Column to use to make new frame’s columns.
However, the error message is confusing now, should raise columns
is not optional.
Code example:
df = pd.DataFrame({"foo": ['one', 'one', 'two', 'two'],"bar": ['A', 'A', 'B', 'C'],"baz": [1, 2, 3, 4]}) df.pivot(columns=None)
KeyError: 'None of [None] are in the columns'