Skip to content
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

Dropna=False is ignored for MultiIndex stack. #3997

Closed
miketkelly opened this issue Jun 22, 2013 · 0 comments · Fixed by #3999

Comments

@miketkelly
Copy link
Contributor

commented Jun 22, 2013


>>> df = pd.DataFrame({'A': ['a1', 'a2'], 'B': ['b1', 'b2'], 'C': [1, 1]})
>>> df
    A   B  C
0  a1  b1  1
1  a2  b2  1

# Unstack introduces some NaNs
>>> df.set_index(['A', 'B']).unstack()
     C    
B   b1  b2
A         
a1   1 NaN
a2 NaN   1

# Stack with dropna=False should keep the NaNs, but doesn't.
>>> df.set_index(['A', 'B']).unstack().stack(dropna=False)
       C
A  B    
a1 b1  1
a2 b2  1

# This is what I expected to get
>>> df.set_index(['A', 'B']).unstack().stack(dropna=False)
        C
A  B     
a1 b1   1
   b2 NaN
a2 b1 NaN
   b2   1

The problem seems to be with reshape.py, line 495 with forces dropna=True.

if isinstance(frame.columns, MultiIndex):
    return _stack_multi_columns(frame, level=level, dropna=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.