maybeyourneighour
maybeyourneighour

Reputation: 494

How to change multiclass labels to binary labels in dataframe

I have a dataset that is labeled with the classes 0-3 and I'm trying to change it so that I can run my classifier with binary labels. So I want to change classes 2 and 3 to class 1. Is there a quick way to do it? Thanks for help

Upvotes: 1

Views: 2668

Answers (2)

0x5961736972
0x5961736972

Reputation: 148

df['column'] = np.where(df.column == "class0", "class0", "class1")

This will effectively leave class0 to class0 only but the remaining classes will be labeled class1.

Upvotes: 0

Tyr
Tyr

Reputation: 610

I guess you have a column that contains 3 types, so below code simply do the task;

df['column'] = df['column'].map({'first_element':1, 'second_element':2,'third_element':3})

Upvotes: 2

Related Questions