-1

I'm working with Pandas, but I have a question about how to change equivalent values. I want to work with binary values in the "class" column so I have 1 and I want 2 and 3 to be changed to 0. Ah! And I don't just have these lines, I have 70 in total! How do I do it?

id  class  col2  col3
0    1     2     0
1    1     1     1
2    1     9     9
3    2     8     4
4    2     7     2
5    2     4     3
6    2     7     2
7    3     1     4
8    3     2     8
9    3     3     9

I want this result:

id  class  col2  col3
 0    1     2     0
 1    1     1     1
 2    1     9     9
 3    0     8     4
 4    0     7     2
 5    0     4     3
 6    0     7     2
 7    0     1     4
 8    0     2     8
 9    0     3     9

1 Answers1

0

Try this:

df.loc[df['class'] > 1, 'class'] = 0