Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #convert #multiple #columns #categorical
ADD COMMENT
Topic
Name
7+4 =