Converting a Pandas Dataframe column into one hot labels

前端 未结 4 1768
余生分开走
余生分开走 2020-12-20 16:08

I have a pandas dataframe similar to this:

  Col1   ABC
0  XYZ    A
1  XYZ    B
2  XYZ    C

By using the pandas get_dummies()

4条回答
  •  失恋的感觉
    2020-12-20 16:48

    if you have a data-frame df with categorical column ABC then you could use to create a new column of one-hot vectors

    df['new_column'] = list(pandas.get_dummies(df['AB]).get_values())
    

提交回复
热议问题