I have a dataframe created form a JSON output that looks like this:
Total Revenue Average Revenue Purchase count Rate
Date
Monday 1,304.40 CA$ 20.07 CA$ 2,345 1.54 %
The value stored are received as string from the JSON. I am trying to:
1) Remove all characters in the entry (ex: CA$ or %) 2) convert rate and revenue columns to float 3) Convert count columns as int
I tried to do the following:
df[column] = (df[column].str.split()).apply(lambda x: float(x[0]))
It works fine except when I have a value with a coma (ex: 1,465 won't work whereas 143 would).
I tried to use several function to replace the "," by "", etc. Nothing worked so far. I always receive the following error:
ValueError: could not convert string to float: '1,304.40'