Skip to content

BUG: Wrong error message is raised when columns=None in df.pivot #30924

Closed
@charlesdong1991

Description

@charlesdong1991

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandasReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions