Skip to content Skip to sidebar Skip to footer

Python Pandas Alterates Values In Floating Point

I have written a Python script which loads one or several csv files, concatenates them and writes the whole into a single new csv file. I have noticed that certain values are modif

Solution 1:

I think you need parameter float_format in to_csv, because floating point precission:

print df.to_csv(float_format='%.3f')
Index,SomeValue
0.000,0.000
1.000,0.000
2.000,0.000
3.000,0.000
4.000,2.527
5.000,0.000

I think you can use round:

df['SomeValue'] = df['SomeValue'].round(3)

Post a Comment for "Python Pandas Alterates Values In Floating Point"