Check if dataframe column is Categorical

后端 未结 5 1927
灰色年华
灰色年华 2020-12-29 00:53

I can\'t seem to get a simple dtype check working with Pandas\' improved Categoricals in v0.15+. Basically I just want something like is_categorical(column) -> True

5条回答
  •  离开以前
    2020-12-29 01:29

    Just putting this here because pandas.DataFrame.select_dtypes() is what I was actually looking for:

    df['column'].name in df.select_dtypes(include='category').columns
    

    Thanks to @Jeff.

提交回复
热议问题