pandas:get_dummies()函数

pandas. get_dummies ( dataprefix=Noneprefix_sep='_'dummy_na=Falsecolumns=Nonesparse=Falsedrop_first=Falsedtype=None ) [source]

Convert categorical variable into dummy/indicator variables,

  • dummy variable是用0或1表示某个类别是否出现

输入的参数:data:array-like, Series, or DataFrame

举例:

title_dum=pd.get_dummies(combined['Title'],prefix='Title')

其中,Title列有六种类型:

  • Officer
  • Royalty
  • Mr
  • Mrs
  • Miss

  • Master

那么,title_dum最后的结果为:

 Title_Master  Title_Miss  Title_Mr  Title_Mrs  Title_Officer  \
0                0           0         1          0              0   
1                0           0         0          1              0   
2                0           1         0          0              0   
3                0           0         0          1              0   
4                0           0         1          0              0   
5                0           0         1          0              0   
 Title_Royalty  
0                 0  
1                 0  
2                 0  
3                 0  
4                 0  
5                 0 

你可能感兴趣的:(pandas:get_dummies()函数)