Changing positive(+) and negative(-) signs to integers in python

  • A+
Category:Languages

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?


You can use:

df.A = df.A.map({'+': 1, '-': -1}) 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: