Python Pandas - Changing some column types to categories

前端 未结 7 1303
孤独总比滥情好
孤独总比滥情好 2021-01-30 01:08

I have fed the following CSV file into iPython Notebook:

public = pd.read_csv(\"categories.csv\")
public

I\'ve also imported pandas as pd, nump

7条回答
  •  梦毁少年i
    2021-01-30 01:32

    Sometimes, you just have to use a for-loop:

    for col in ['parks', 'playgrounds', 'sports', 'roading']:
        public[col] = public[col].astype('category')
    

提交回复
热议问题