简体   繁体   中英

How to create a target from multiple columns to train a classification model?

DataFrame head sample: 在此处输入图像描述 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM