Selecting rows by value in a floating point column in pandas
<p>I import a csv data file into a pandas DataFrame <code>df</code> with <code>pd.read_csv</code>. The text file contains a column with strings like these:</p>

<pre><code>y
0.001
0.0003
0.0001
3e-05
1e-05
1e-06
</code></pre>

<p>If I print the DataFrame, pandas outputs the decimal representation of these values with 6 digits after the comma, and everything looks good.</p>

<p>When I try to select rows by value, like <a href="https://stackoverflow.com/questions/17071871/select-rows-from-a-dataframe-based-on-values-in-a-column-in-pandas">here</a>:</p>

<pre><code>df[df['y'] == value],
</code></pre>

<p>by typing the corresponding decimal representation of value, pandas correctly matches certain values (example: rows 0, 2, 4) but <strong>does not</strong> match others (rows 1, 3, 5). This is of course due to the fact that those rows values do not have a perfect representation in base two. </p>

<p>I was able to workaround this problem is this way:</p>

<pre><code>df[abs(df['y']/value-1) &lt;= 0.0001]
</code></pre>

<p>but it seems somewhat awkward. What I'm wondering is: numpy already has a method, <a href="http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.isclose.html" rel="nofollow noreferrer">.isclose</a>, that is specifically for this purpose. </p>

<p>Is there a way to use <code>.isclose</code> in a case like this? Or a more direct solution in pandas?</p>