I'm trying to understand how can I address columns after using get_dummies
.
For example, let's say I have three categorical variables.
first variable has 2 levels.
second variable has 5 levels.
third variable has 2 levels.
df=pd.DataFrame({"a":["Yes","Yes","No","No","No","Yes","Yes"], "b":["a","b","c","d","e","a","c"],"c":["1","2","2","1","2","1","1"]})
I created dummies for all three variable in order to use them in sklearn
regression in python.
df1 = pd.get_dummies(df,drop_first=True)
Now I want to create two interactions (multiplication): bc , ba
how can I create the multiplication between each dummies variable to another one without using their specific names like that:
df1['a_yes_b'] = df1['a_Yes']*df1['b_b']
df1['a_yes_c'] = df1['a_Yes']*df1['b_c']
df1['a_yes_d'] = df1['a_Yes']*df1['b_d']
df1['a_yes_e'] = df1['a_Yes']*df1['b_e']
df1['c_2_b'] = df1['c_2']*df1['b_b']
df1['c_2_c'] = df1['c_2']*df1['b_c']
df1['c_2_d'] = df1['c_2']*df1['b_d']
df1['c_2_e'] = df1['c_2']*df1['b_e']
Thanks.