-1

I have a DataFrame that is all numeric and contains some error values such as :10..9,10...9 etc. I want to keep only one decimal place. What do I do with that?

DYZ
  • 55,249
  • 10
  • 64
  • 93
cscny
  • 39
  • 3

1 Answers1

0

Example data:

values = ['10.9', '10..9', '10...9']

Using re:

list(map(lambda x: float(re.sub('\.+', '.', x)), values))
[10.9, 10.9, 10.9]

Using pandas:

s = pd.Series(values)
s.str.replace('\.+', '.').astype(float)

0    10.9
1    10.9
2    10.9
dtype: float64
Cainã Max Couto-Silva
  • 4,839
  • 1
  • 11
  • 35