'column transformer on dataframe for one-hot encoding

                                         3      4  \
0      macrolide-lincosamide-streptogramin   macB   
1      macrolide-lincosamide-streptogramin   macB   
2                                multidrug   cmeB   
3      macrolide-lincosamide-streptogramin   macA   
4                            pleuromutilin   TaeA   
...                                    ...    ...   
17277                         trimethoprim  dfrB7   
17278                          sulfonamide   folp   
17279                             rifampin   rpoB   
17280                             rifampin   rpoB   
17281                            elfamycin  tufab   

                                   5  6  \
0       antibiotic target protection  0   
1                  antibiotic efflux  0   
2                  antibiotic efflux  0   
3                  antibiotic efflux  0   
4                  antibiotic efflux  0   
...                              ... ..   
17277  antibiotic target replacement  0   
17278   antibiotic target alteration  0   
17279   antibiotic target alteration  0   
17280   antibiotic target alteration  0   
17281   antibiotic target alteration  0   

I have dataframe which I would like to one-hot encode. however, in order to do it, I read that I column transformer is needed, so that the data type matches the requirement for one-hot encoding. Since the column number may be added in the future as the datasets expand, I would like to create command line that has the capacity to do so instead of specifying the number of the column that I want to transform. Is there anyone who knows how to do so?

Thank you for your help in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source