I hope you can help me with this question. I have a column with numeric values as strings. Since they are data from diferent countries, some of them have different formats such as "," and "$". I'm trying to convert the serie to numbers, but i'm having trouble with "," and "$" values.
data={"valores":[1,1,3,"4","5.00","1,000","$5,700"]}
df=pd.DataFrame(data)
df
valores
0 1
1 1
2 3
3 4
4 5.00
5 1,000
6 $5,700
Ive tried the following:
df["valores"].replace(",","")
but it does not change a thing since the "," value is in the string, not the string value itself
pd.to_numeric(df["valores"])
But I receive the "ValueError: Unable to parse string "1,000" at position 5" error.
valores=[i.replace(",","") for i in df["valores"].values]
But I receive the "AttributeError: 'int' object has no attribute 'replace' error.
So, at last, I tried with this:
valores=[i.replace(",","") for i in df["valores"].values if type(i)==str]
valores
['4', '5.00', '1000', '$5700']
But it skipped the first three values since they are not strings..
I think that with a Regex code i would be able to manage it, but I just simply dont understand how to work with it.
I hope you can help me since i've been struggling with this for about 7 hours.