import pandas as pd
from sklearn.preprocessing import LabelEncoder
用pandas读取数据
第一种方法:
le =LabelEncoder()
le.fit(['Female','Male'])
data_tran['gender']=le.transform(data['gender'])
第二种方法:
data_tran['MultipleLines']=le.fit_transform(data['MultipleLines'])
找到标号对应的值
print(le.inverse_transform([0,1,2]))
['No' 'No phone service' 'Yes']
排序是按照字典序