Python数值数据处理

Python数值数据处理,python,pandas,numpy,Python,Pandas,Numpy,我有一个全是数字的数据帧,包含一些错误值,例如:10..9,10..9等。我只想保留一个小数位。我该怎么办?示例数据: values = ['10.9', '10..9', '10...9'] list(map(lambda x: float(re.sub('\.+', '.', x)), values)) [10.9, 10.9, 10.9] s = pd.Series(values) s.str.replace('\.+', '.').astype(float) 0 10.9 1

我有一个全是数字的数据帧,包含一些错误值,例如:10..9,10..9等。我只想保留一个小数位。我该怎么办?

示例数据:

values = ['10.9', '10..9', '10...9']
list(map(lambda x: float(re.sub('\.+', '.', x)), values))
[10.9, 10.9, 10.9]
s = pd.Series(values)
s.str.replace('\.+', '.').astype(float)

0    10.9
1    10.9
2    10.9
dtype: float64
使用
re

values = ['10.9', '10..9', '10...9']
list(map(lambda x: float(re.sub('\.+', '.', x)), values))
[10.9, 10.9, 10.9]
s = pd.Series(values)
s.str.replace('\.+', '.').astype(float)

0    10.9
1    10.9
2    10.9
dtype: float64
使用
熊猫

values = ['10.9', '10..9', '10...9']
list(map(lambda x: float(re.sub('\.+', '.', x)), values))
[10.9, 10.9, 10.9]
s = pd.Series(values)
s.str.replace('\.+', '.').astype(float)

0    10.9
1    10.9
2    10.9
dtype: float64

你可以四舍五入到小数点后一位。这很容易查到。你被困在哪里了?示例中的数据不是数字。是的,因为Python中没有像用户提供的那样有两点的数字。我假设OP实际上有字符串,并且想要去掉额外的点(为了使它们成为数字)。这就是为什么,我认为,用户在标签中做了
re
。但我可能错了。