I want to calculate with a value in my dataframe, however, this string consists of an exponential number (’10⁻³’). Is this some kind of encoding issue? How can I convert this string into a float (e.g. 10e-3) so that can perform calculations with this value?
(using Python 3.8.8)
Advertisement
Answer
First problem is to convert the Unicode symbols to something easier to work with.
JavaScript
x
3
1
import unidecode
2
simpler = unidecode.unidecode('10⁻³')
3
Now you can put an ‘e’ in front of any ‘-‘ or ‘+’:
JavaScript
1
2
1
simpler = simpler.replace('-', 'e-').replace('+', 'e+')
2
Now you have a format you can give to float
.
JavaScript
1
2
1
f = float(simpler)
2