pivot_table
with margins=True
shows NaN
with Period
columns · Issue #28323 · pandas-dev/pandas (original) (raw)
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