Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中,在同一个单元中进行数字浮动_Python_Pandas_Dataframe - Fatal编程技术网

在python中,在同一个单元中进行数字浮动

在python中,在同一个单元中进行数字浮动,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个熊猫系列(float64),有以下问题: series = pd.Series([3.65, 37.8, 0.3800, 3.9, 3.10, 3111.12, np.nan, 0.32, 3.3, 3.4 ]) 如何使所有浮动一致(即具有相同的刻度/单位) 这种情况下的预期结果应为: series_corrected = pd.Series([3.65, 3.78, 3.800, 3.9, 3.10, 3.11112, np.nan, 3.2, 3.3, 3.4 ]) 我们可以使用

我有一个熊猫系列(float64),有以下问题:

series = pd.Series([3.65, 37.8, 0.3800, 3.9, 3.10, 3111.12, np.nan, 0.32, 3.3, 3.4 ])
如何使所有浮动一致(即具有相同的刻度/单位)

这种情况下的预期结果应为:

series_corrected = pd.Series([3.65, 3.78, 3.800, 3.9, 3.10, 3.11112, np.nan, 3.2, 3.3, 3.4 ])

我们可以使用字符串编辑来执行以下操作,但这取决于您的真实数据

s = series.astype(str).str.findall('\d+').str.join('').str.strip('0')
s = pd.to_numeric(s.str[0]+'.'+s.str[1:],errors='coerce')
s
0    3.65000
1    3.78000
2    3.80000
3    3.90000
4    3.10000
5    3.11112
6        NaN
7    3.20000
8    3.30000
9    3.40000
dtype: float64