Convert categorical data in pandas dataframe

后端 未结 10 1885
予麋鹿
予麋鹿 2020-11-27 10:01

I have a dataframe with this type of data (too many columns):

col1        int64
col2        int64
col3        category
col4        category
col5        categ         


        
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 10:26

    This works for me:

    pandas.factorize( ['B', 'C', 'D', 'B'] )[0]
    

    Output:

    [0, 1, 2, 0]
    

提交回复
热议问题