Skip to content

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

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

Closed
lodagro opened this issue Dec 23, 2011 · 3 comments
Closed

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

lodagro opened this issue Dec 23, 2011 · 3 comments
Labels
Milestone

Comments

@lodagro
Copy link
Contributor

lodagro commented Dec 23, 2011

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?

@lodagro
Copy link
Contributor Author

lodagro commented Jan 5, 2012

Noticed that issue #477 already describes fact that DataFrame.unstack() raises exception in case of single level row index, the issue does not mention documentation.

@ghost ghost assigned adamklein Jan 9, 2012
wesm pushed a commit that referenced this issue Jan 9, 2012
Conflicts:

	pandas/core/frame.py
@wesm
Copy link
Member

wesm commented Jan 9, 2012

Made a pass over these docstrings. Looking good

@wesm wesm closed this as completed Jan 9, 2012
@GuillaumeDesforges
Copy link

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?

Any update about that ? Would be helpful !

dan-nadler pushed a commit to dan-nadler/pandas that referenced this issue Sep 23, 2019
Clean orphaned versions before prune (issue pandas-dev#531)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants