If you are working in machine learning then I am sure you will need this code many times. Use the below piece of code for one hot encoding.
cat_vars=['LeadSource','Products__c','Service_Offering__c'] for var in cat_vars: cat_list='var'+'_'+var cat_list = pd.get_dummies(dataset2[var], prefix=var) dataset3=dataset3.join(cat_list) cat_vars=['LeadSource','Products__c','Service_Offering__c'] data_vars=dataset3.columns.values.tolist() to_keep=[i for i in data_vars if i not in cat_vars] data_final=dataset3[to_keep] data_final.columns.values
If you face any issue in implementing above code snippet feel free to write to me.
Happy Coding!!
Leave a Reply