Ignoring symbols and select only numerical values with pandas
-
16-10-2019 - |
Question
In one field I have entries like 'U$ 192,0'. Working on pandas, how I ignore non numerical data and get only the numerical part?
Solution
Use str.strip
if the prefix is fixed or str.replace
if not:
data = pandas.Series(["U$ 192.0"])
data.str.replace('^[^\d]*', '').astype(float)
This removes all the non-numeric characters to the left of the number, and casts to float.
Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange