-2

i have a dataframe where i have identified 5 columns which need to be converted to dummies, but i am not able to create dummies from multiple columns. The entire dataframe is numerical in nature, no categorical values. consider i have 100 variables which i have, and out of those 100 columns, 5 should be converted to dummies. namely V1,V4,V5,V15,V52.. how can i do it, i can't find any syntax for that, that worked for me, how to create dummies out of multiple columns in a single dataframe and concat all the dummies in the original dataframe.

i've tried this code, but so far it didn't work

new_dum = ['V1','V4','V5','V15','V52']
dumy_col = pd.get_dummies(traindf[new_dum], drop_first = True)
dumy_col

This is the output that i got

This is the output that i got

1 Answers1

0

This syntax worked

dumy_col = pd.get_dummies(traindf, columns=['V1','V4','V5','V6','V44'], 
drop_first = True)
dumy_col