python值错误:

2024-09-30 05:27:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用下面的代码创建虚拟变量

    cat_vars=['Gender', 'Recidence', 'CivilStatus', 'HighestEducationQualification', 'ExtraCurricularActivities', 'ApparelRelatedVocationalQualification', 'PreviouseJob', 'ExperienceSection', 'RelativesInApparel', 'SpousesOccupation', 'FamilyOppinionAboutTheJob', 'ExpectationOfDoingTheJob', 'AvailabilityOfTransportNearTheResidence', 'ReasonForChooseApparel', 'PreviousWorkPlace', 'ContributionToTheFamilyIncome', 'PersonalImpression', 'AccommodationFee', 'RetentionCategory', 'SelectedDepartment', 'ChildrenLessThan5Years', 'NumberOfChilren', 'ApparelExperience', 'ReasonForLeaving', 'MedicalTest', 'ExpectedSalary', 'ExperienceDurationMonths', 'IQTestScore', 'LastBasicSalary', 'InterviewedBy', 'FollowingExternalCourses', 'Is_Rejoined_Employee__c']
for var in cat_vars:
    cat_list='var'+'_'+var
    cat_list = pd.get_dummies(df[var], prefix=var)
    data1=df.join(cat_list)

但它不断抛出这个错误

columns overlap but no suffix specified: Index(['Gender_Female', 'Gender_Male'], dtype='object')


Tags: 代码dfvarvarsgenderlistcat试图用

热门问题