该列中包含了标签中的所有类别:
from sklearn.preprocessing import OneHotEncoder
enc = OneHotEncoder(sparse = False)
result = enc.fit_transform(data[[41]]) #41指的是列标为41的那一列数据
该列中包含了标签中的所有类别的一部分:
from sklearn.preprocessing import OneHotEncoder
enc = OneHotEncoder(sparse = False)
enc.fit([[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]])
result = enc.transform(data[[41]]) #注意这个函数少了fit前缀
#enc = OneHotEncoder(sparse = False)
#enc.fit([[0], [1]])
#result = enc.transform(data['6A'])
#print(result.shape)
s=pd.get_dummies(data['6A'],sparse=True)
来源:CSDN
作者:ACSE-Mayer
链接:https://blog.csdn.net/sunmingyang1987/article/details/103767624