0

I want to take difference of each column data and see if it is equal to 0.6. I am using pandas (v2.0.2) read_csv to try to accomplish this.

main.py:

import pandas as pd

file = "C:/Users/Documents/proj/data.csv"

df = pd.read_csv(file)

out = df["colA"].diff().eq(0.6)
print(out)

The output I get is:

0    False
1    False
2    False
3    False

The expected output should be:

0    False
1    True
2    True
3    True

data.csv contains:

colA
1.2
1.8
2.4
3

I don't understand why this is not working - Any suggestion is much appreciated

sapphire
  • 13
  • 4
  • 1
    Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) look at the `abs(1.2-1.8)`, which does not equal `.6` – It_is_Chris Jun 01 '23 at 20:08
  • 2
    Try using `isclose()` instead of `eq()`. https://stackoverflow.com/questions/33626443/comparing-floats-in-a-pandas-column – Barmar Jun 01 '23 at 20:09
  • Thanks, this is what I was looking for – sapphire Jun 04 '23 at 08:05

0 Answers0