Loan_ID    Gender  Married Dependents  Education   ApplicantIncome
1   LP001003    Male     Yes        1       Graduate       4583
2   LP001005    Male     Yes        0       Graduate       3000
3   LP001006    Male     Yes        0       Not Graduate   2583
4   LP001008    Male     No         0       Graduate       6000
5   LP001011    Male     Yes        2       Graduate       5417



  如何在不影响“性别”,“已婚”,“教育”列的情况下进行编码
  “贷款ID”,“受抚养者”,“申请人收入”列。

最佳答案

这应该可以解决您的问题。

from sklearn.preprocessing import LabelEncoder

le = LabelEncoder()

for cat_var in ['Gender', 'Married', 'Education']:
    df[cat_var] = le.fit_transform(df[cat_var])

关于python - 如何在不影响DataFrame中的数字数据的情况下对分类数据进行编码?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58969758/

10-12 21:17