Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
import numpy as np
df = pd.DataFrame({"A": ["10", ""], "B": ["one", "two"], "D": [1, 2]})
table = pd.pivot_table(df, values='D', index=['A', 'B'], aggfunc=np.sum, dropna=False)
Issue Description
df | | A | B | D | |---:|:----|:----|----:| | 0 | 10 | one | 1 | | 1 | | two | 2 |
table | | D | |:--------------|----:| | ('', 'one') | nan | | ('', 'two') | 2 | | ('10', 'one') | 1 | | ('10', 'two') | nan |"
Rows 1 and 4 are obviously redundant.
Expected Behavior
D | |
---|---|
('', 'two') | 2 |
('10', 'one') | 1 |
Installed Versions
Comment From: phofl
Hi, thanks for your report. This is independent of empty strings and I think this behaves as expected, but not sure
Comment From: alexey-buzuverov
Thanks for clarification. It simply takes all possible index permutations to make table rows when dropna=False
.