0

When I'm trying to access a specific value in my pandas dataframe, the output provides me with a tiny number (0.0000000000000001) adding to my original value. Why is this happening and how can I stop it?

The data is read in from a csv to a pandas dataframe, which has the value 1.009 contained in it (the csv is exactly 1.009), but when I try and access the value from it, specifying the column, then it gives me 1.0090000000000001. I don't want to simply round the number to x decimal places as my values have varying amounts of decimal places.

print(data_final.iloc[328])

# gives:
# independent    1.009
# dependent      7.757
# Name: 328, dtype: float64

print(data_final.iloc[328,0])

#gives: 1.0090000000000001

print(data_final['independent'].iloc[328])

#gives: 1.0090000000000001

I expected the output to be 1.009 however it is 1.0090000000000001!

  • 1
    This just looks like a regular floating point error. Floats aren't 100% accurate I'm afraid due to the nature of the calculations. – michjnich Aug 22 '19 at 08:36
  • 1
    This is called floating point broken read here: https://stackoverflow.com/questions/588004/is-floating-point-math-broken. to avoid this perform round to two digits :) – Mohamed Thasin ah Aug 22 '19 at 08:36

0 Answers0