Python 按特定值选择行时出现棘手的错误

Python 按特定值选择行时出现棘手的错误,python,python-2.7,pandas,Python,Python 2.7,Pandas,我上传了我的文件,并希望根据某些功能的值选择某些样本(行) 以下是我的尝试: df[df['Sample_ID'] == '160606-6']['OC_unc'].values >array([ 0.9874218, 1.089288 ]) # just locate to the sample with ["OC_unc] == 0.9874218 df.loc[df['OC_unc'] == 0.9874218] > No result 我不知道为什么这个方法在使用浮点数

我上传了我的文件,并希望根据某些功能的值选择某些样本(行)

以下是我的尝试:

df[df['Sample_ID'] == '160606-6']['OC_unc'].values
>array([ 0.9874218,  1.089288 ])
 # just locate to the sample with ["OC_unc] == 0.9874218
df.loc[df['OC_unc'] == 0.9874218]
> No result

我不知道为什么这个方法在使用浮点数据时失败。我试着用字符串列表选择行,它总是工作得很好

我怀疑这与pandas中的浮点截断有关。考虑下面的例子:

>>> df = pd.DataFrame([1.00000000001], columns=['test'])
>>> df
   test
0   1.0
>>> df.loc[df['test'] == 1.0]
Empty DataFrame
Columns: [test]
Index: []
解决此问题的一种方法是使用
pd.set\u选项
提高显示精度:

>>> pd.set_option('precision', 15)
>>> df
            test
0  1.00000000001
>>> df.loc[df['test'] == 1.00000000001]
            test
0  1.00000000001