Trying to categorize some columns and exclude others. Getting this error Cannot perform 'ror_' with a dtyped [object] array and scalar of type [bool]

16 views Asked by At

I would like to exclude ratings column and correctYear column from getting categorized. I would like to categorize every other object type field but leave out these two because they are numeric values.

name            object
rating          object
genre           object
year             int64
released        object
score          float64
votes          float64
director        object
writer          object
star            object
country         object
budget         float64
gross          float64
company         object
runtime        float64
correctYear     object
dtype: object

below is my code

tried type casting correctYear but got this error

could not convert string to float:
df_cat = df

for col in df_cat.columns:
    if (df_cat[col].dtype=='object' & (df_cat[col]!='rating' | df_cat[col]!='correctYear')):
        df_cat[col] = df_cat[col].astype('category')
        df_cat[col] = df_cat[col].cat.codes

Any help would be greatly appreciated :)

0

There are 0 answers