What is a good heuristic to detect if a column in a pandas.DataFrame is categorical?

后端 未结 7 691
旧时难觅i
旧时难觅i 2021-02-01 18:12

I\'ve been developing a tool that automatically preprocesses data in pandas.DataFrame format. During this preprocessing step, I want to treat continuous and categorical data dif

7条回答
  •  难免孤独
    2021-02-01 18:53

    You could define which datatypes count as numerics and then exclude the corresponding variables

    If initial dataframe is df:

    numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']
    dataframe = df.select_dtypes(exclude=numerics)
    

提交回复
热议问题