Ожидается, поскольку в столбце есть строковые значения, поэтому при повторном преобразовании из float
возникает ошибка:
df = pd.DataFrame({'rMeanPSFMag':[10.10235, 45.45871]})
print(df['rMeanPSFMag'].apply(type))
0 <class 'float'>
1 <class 'float'>
Name: rMeanPSFMag, dtype: object
#convert floats to strings with 3 decimals
df['rMeanPSFMag'] = df['rMeanPSFMag'].map('{:,.3f}'.format)
print(df)
rMeanPSFMag
0 10.102
1 45.459
print(df['rMeanPSFMag'].apply(type))
0 <class 'str'>
1 <class 'str'>
Name: rMeanPSFMag, dtype: object
Если требуется с плавающей запятой до 3 decimal
s, используйте round
:
df['rMeanPSFMag'] = df['rMeanPSFMag'].round(3)
print (df)
rMeanPSFMag
0 10.102
1 45.459
print(df['rMeanPSFMag'].apply(type))
0 <class 'float'>
1 <class 'float'>
Name: rMeanPSFMag, dtype: object
Другое решение кратно 1000
, преобразовать в integer
с и разделить на 1000
:
df['rMeanPSFMag'] = df['rMeanPSFMag'].mul(1000).astype(int).div(1000)
print (df)
rMeanPSFMag
0 10.102
1 45.458