Skip to content

pandas.DataFrame.unstack() documentation example has errors #14206

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
ghost opened this issue Sep 12, 2016 · 3 comments · Fixed by #14211
Closed

pandas.DataFrame.unstack() documentation example has errors #14206

ghost opened this issue Sep 12, 2016 · 3 comments · Fixed by #14211
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Sep 12, 2016

The last part of the documentation says

>>> df = s.unstack(level=0)
>>> df.unstack()
one  a  1.
     b  3.
two  a  2.
     b  4.

although we'd have

>>> import pandas as pd
>>> index = pd.MultiIndex.from_tuples([('one', 'a'), ('one', 'b'),
...                                     ('two', 'a'), ('two', 'b')])
>>> import numpy as np
>>> s = pd.Series(np.arange(1.0, 5.0), index=index)
>>> s
one  a    1.0
     b    2.0
two  a    3.0
     b    4.0
dtype: float64
>>> s.unstack(level=-1)
       a    b
one  1.0  2.0
two  3.0  4.0
>>> s.unstack(level=0)
   one  two
a  1.0  3.0
b  2.0  4.0
>>> df = s.unstack(level=0)
>>> df.unstack()
one  a    1.0
     b    2.0
two  a    3.0
     b    4.0
dtype: float64
@jorisvandenbossche
Copy link
Member

Hmm, I thought this was already fixed before, but apparently not ..

PR to fix this very welcome!

@jorisvandenbossche
Copy link
Member

Seems that I corrected one of the examples a long time ago, but not that last one :-) #4776

@sudk1896
Copy link

@jorisvandenbossche : Hey, I have created the PR including the suggestions mentioned in the thread, kindly take a look.

@jreback jreback added this to the 0.19.0 milestone Sep 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants