I have a column 'type' with the variables - normal, scalar, linear, perpendicular, tabular
I have to rewrite this column whereby all values that are 'normal' have to be replaced by -1, and everything else by 1. Input being as follows:
type:
normal
normal
tabular
scalar
normal
linear
and the expected output
type
-1
-1
1
1
-1
1
For this, I have tried:
data.loc[data['type'] != 'normal', 'type'] = -1
This one is just converting all attributes in the column to -1. Plus, when I do this:
data.loc[data['type'] == 'normal', 'type'] = 1
It's not having any effect and all attributes still remain -1 (both normal and others). Can someone help me with this.
Additionally, in another part of the project, I have to apply an undersampling technique to obtain a balanced set of data where all samples with value 'normal' shall belong to negative class, and all others to positive class. I'm kind of stuck with both these problems being similar in nature.