Skip to content

Selecting a categorial column returns a DataFrame #12998

@rsdenijs

Description

@rsdenijs

I am not 100% sure if this is a bug, but it generates very unexpected behaviour!
Essentially, if columns are of type Categorical, selecting a single one using df[column_name] a DataFrame is returned, unlike for columns of other types, for which a Series would be returned.

Code Sample, a copy-pastable example if possible

print pd.DataFrame([[1,2]], columns=['a','b'])['a'].__class__
print pd.DataFrame([[1,2]], columns=pd.Categorical(['a','b']))['a'].__class__

produces


<class 'pandas.core.series.Series'>  <--- Ok....
<class 'pandas.core.frame.DataFrame'> <----- What?!

Expected Output

<class 'pandas.core.series.Series'>
<class 'pandas.core.series.Series'>

output of pd.show_versions()

pandas: 0.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugCategoricalCategorical Data TypeDuplicate ReportDuplicate issue or pull requestIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions