change all object columns to categorical pandas code example
Example 1: pandas convert multiple columns to categorical
#Two ways to do this
df[['parks', 'playgrounds', 'sports']].apply(lambda x: x.astype('category'))
cols = ['parks', 'playgrounds', 'sports', 'roading']:
public[cols] = public[cols].astype('category')
Example 2: how to make a column a factor in pandas
df['col_name'] = df['col_name'].astype('category')