Skip to content

crosstab dropna=False breaks columns.names #12133

Closed
@Winand

Description

@Winand

Specifying dropna=False drops column level names:

import pandas as pd
df = pd.DataFrame({"Col1": [23], "Col2": [45]})
names1 = pd.crosstab(df["Col1"], df["Col2"]).columns.names
names2 = pd.crosstab(df["Col1"], df["Col2"], dropna=False).columns.names
print(names1, names2)
>>>['Col2'] [None]

P.S. At first i thought dropna=False will help to count NaN values, though it seems that fillna is needed. So i don't understand, why this parameter is needed at all. If entire column is NaN then we'll get KeyError: '__dummy__' anyway.

pandas: 0.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions