Skip to content

DataFrame.stack() DataFrame.unstack() documentation/behavior #531

@lodagro

Description

@lodagro

DataFrame.stack() and DataFrame.unstack() methods require docstring update.

DataFrame.stack() docstring mentions that method converts DataFrame to Series, and returns a Series. This is only the case when columns has only one level. In case columns has multiple levels, method returns a DataFrame.

DataFrame.unstack() docstring is mainly a copy of the Series.unstack() docstring, example should operate on a DataFrame and not a Series.
Concerning the behavior, when the DataFrame index is a single level one, unstack() raises:

AttributeError: `Index` object has no attribute `levels`

DataFrame.unstack() assumes a DataFrame with a multilevel index, it can not operate on single level index, maybe the method could return a Series in case unstack() operates on DataFrame with single level index, similar as stack() does in case of single level columns?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions