Any way to get mappings of a label encoder in Python pandas?

前端 未结 8 1764
清酒与你
清酒与你 2021-02-01 15:11

I am converting strings to categorical values in my dataset using the following piece of code.

data[\'weekday\'] = pd.Categorical.from_array(data.weekday).labels         


        
8条回答
  •  青春惊慌失措
    2021-02-01 15:23

    First, make a categorical series:

    weekdays = pd.Series(['Sun', 'Sun', 'Wed', 'Mon', 'Mon']).astype('category')
    

    Then, inspect its "categories":

    weekdays.cat.categories.get_loc('Sun')
    

提交回复
热议问题