Skip to content

BUG: Stack creates duplicate column #39481

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
soerenwolfers opened this issue Jan 30, 2021 · 4 comments · Fixed by #39507
Closed

BUG: Stack creates duplicate column #39481

soerenwolfers opened this issue Jan 30, 2021 · 4 comments · Fixed by #39507
Labels
Bug MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@soerenwolfers
Copy link

import numpy as np
import pandas as pd

df = pd.DataFrame(
    np.zeros([1, 5]), 
    columns=pd.MultiIndex.from_tuples(
        [
            (0, None, None), 
            (0, 0, 0),
            (0, 0, 1),
            (0, 1, 0),
            (0, 1, 1),
        ],
    )
)

image

df.stack(2)

image


INSTALLED VERSIONS
------------------
commit           : b5958ee1999e9aead1938c0bba2b674378807b3d
python           : 3.6.6.final.0
pandas           : 1.1.5
numpy            : 1.17.4
@soerenwolfers soerenwolfers changed the title Pandas stack creates duplicate column BUG: Stack creates duplicate column Jan 30, 2021
@phofl
Copy link
Member

phofl commented Jan 31, 2021

That is not really a duplicate, the first 1 is representing the NaN. The MultiIndex handling was not correct.

@phofl phofl added MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jan 31, 2021
@soerenwolfers
Copy link
Author

Right, my original problem was that I got an error when trying to stack both the last two levels of the columns. Error message said something about duplicate columns, and when I made the MWE it seemed to fit

@aelshazlyIT
Copy link

might be the MultiIndex handling was not correct.

@phofl
Copy link
Member

phofl commented Feb 1, 2021

That is not really a duplicate, the first 1 is representing the NaN. The MultiIndex handling was not correct.

Yes, is fixed in my pr

@jreback jreback added this to the 1.3 milestone Feb 4, 2021
@jreback jreback added the Bug label Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants