I have a question - how to insert multiple (for example 3) columns to the DataFrame on the location of an existing column? In other words, I had a column with some categorical values which I encode with one-hot encoding - as a result, I obtained 3 new columns. Now, I want to drop the original column and insert resulting columns on its location (and not to the end of data frame). Any ideas of how to do it efficiently? I'll appreciate any help.
**df1 - Original datafarme** :
col1 col2 col3
0 4 A 0.5
1 5 B 0.78
2 6 C 0.55
3 7 A 0.78
**df2 - created one-hot encoding of categorical col2** :
col2_A col2_B col2_C
0 1 0 0
1 0 1 0
2 0 0 1
3 1 0 0
How to insert columns of df2 to df1, instead of col2 to obtain:
**Updated df1**
col1 col2_A col2_b col2_C col3
0 4 1 0 0 0.5
1 5 0 1 0 0.78
2 6 0 0 1 0.55
3 7 1 0 0 0.78