Skip to content

API: preferred way to check if column/Series has Categorical dtype #8814

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

From http://stackoverflow.com/questions/26924904/check-if-dataframe-column-is-categorical/26925340#26925340

What is the preferred way to check for categorical dtype?

I now answered:

In [42]: isinstance(df.cat_column.dtype, pd.core.common.CategoricalDtype)
Out[42]: True

In [43]: pd.core.common.is_categorical_dtype(df.cat_column)
Out[43]: True

But:

  • this seems somewhat buried in pandas. Should there be a more top-level function to do this?
  • we should add the preferred way to the categorical docs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions