I have a dataframe with the following column:
A
+
+
-
+
-
How do I convert this column into integer values. So that I could multiply it to other numerical values?
Therefore, all '+' would be replaced by 1 and '-' by -1.
You can use:
df.A = df.A.map({'+': 1, '-': -1})
If I understand correctly, you could just use replace
:
>>> df
A
0 +
1 +
2 -
3 +
4 -
new_df = df.replace({'A':{'+':1, '-':-1}})
>>> new_df
A
0 1
1 1
2 -1
3 1
4 -1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With