首页 > 解决方案 > Equality operation does not work for Pandas dataframe value in one or more cells but work for others

问题描述

I am working with dataframes read from csv file using pandas. I wanted to do some equality operation to find the rows where the column is of a specific value. However, it seems that the equality operation works for some numbers but not for others.

sample[sample['Time'] == 34200.045021468].index
Out[68]: Int64Index([], dtype='int64')

sample.loc[40, ['Time']]

Out[69]: 
Time    34200.045021468
Name: 40, dtype: float64
sample[sample['Time'] == 34200.647527227].index
Out[71]: Int64Index([170, 171, 172, 173, 174], dtype='int64')

I have not tried for all values but when I tried to search for the value 34,200.045021468, it did not find anything but as can be seen it does exist in my dataframe.

On the other hand, when I do the same operation for another value, 34,200.647527227, it works?!

Can anyone kindly advise on what is wrong and how it can be fixed? Thank you in advance

标签: pythonpandasfloating-pointequality

解决方案


推荐阅读