Skip to content

pivot_table with margins=True shows NaN with Period columns #28323

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
lucatrv opened this issue Sep 6, 2019 · 1 comment · Fixed by #28354
Closed

pivot_table with margins=True shows NaN with Period columns #28323

lucatrv opened this issue Sep 6, 2019 · 1 comment · Fixed by #28354
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@lucatrv
Copy link

lucatrv commented Sep 6, 2019

The following code reproduces the issue:

import pandas as pd

df = pd.DataFrame(
    {
        "a": [1, 1, 2, 2],
        "b": [
            pd.Period("2019Q1"),
            pd.Period("2019Q2"),
            pd.Period("2019Q1"),
            pd.Period("2019Q2"),
        ],
        "x": 1.0,
    }
)

df.pivot_table(index="a", columns="b", values="x", margins=True)

Output:

b 	2019Q1 	2019Q2 	All
a 			
1 	1.0 	1.0 	1.0
2 	1.0 	1.0 	1.0
All	NaN 	NaN 	1.0

Expected output:

b 	2019Q1 	2019Q2 	All
a 			
1 	1.0 	1.0 	1.0
2 	1.0 	1.0 	1.0
All	1.0 	1.0 	1.0
@WillAyd
Copy link
Member

WillAyd commented Sep 7, 2019

Thanks for the note. If you'd like to investigate and submit a PR would certainly welcome that

@WillAyd WillAyd added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Sep 7, 2019
@WillAyd WillAyd added this to the Contributions Welcome milestone Sep 7, 2019
@jreback jreback modified the milestones: Contributions Welcome, 1.0 Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants