Home > Software design >  How to create a target from multiple columns to train a classification model?
How to create a target from multiple columns to train a classification model?

Time:09-27

DataFrame head sample: enter image description here Where I need to create a new feature of the name category which will contain sarcastic category data like data from the last six columns should combine to make the new column and the values in that column should be labeled as per the column's name of the last five columns.

CodePudding user response:

Use df.loc['category A' = 1, 'category'] = 'category A' for all possible categories:

categories = ['sarcasm', 'irony', 'satire', 'understatement', 'overstatement', 'rhetorical_question']
for category in categories:
    df.loc[df[category] == 1, 'category'] = category
  • Related