I’m trying to extract a price value as float in python. The price comes as Rs.95.00
one = float(''.join(c for c in price_laughs if (c.isdigit() or c =='.')))
print(one)
I tried to extract the price using the following code, but since there’s a ‘.’ at the beginning, i’m unable to get the value as 95.00. How can i extract the price as a float value.
>Solution :
If the value is always going to contain Rs., one way is to split one time from left passing maxsplit=1 then to get the last value.
>>> v='Rs.95.00'
>>> float(v.split('.', 1)[-1])
95.0