Pandas: Group by rounded floating number
<p>I have a dataframe with a column of floating numbers. For example:</p>

<pre><code>df = pd.DataFrame({'A' : np.random.randn(100), 'B': np.random.randn(100)})
</code></pre>

<p>What I want to do is to group by column A after rounding column A to 2 decimal places.</p>

<p>The way I do it is highly inefficient:</p>

<pre><code>df.groupby(df.A.map(lambda x: "%.2f" % x))
</code></pre>

<p>I particularly don't want to convert everything to a string, as speed becomes a huge problem. But I don't feel it is safe to do the following:</p>

<pre><code>df.groupby(np.around(df.A, 2))
</code></pre>

<p>I am not sure, but I feel that there might be cases where two float64 numbers will have the same string representation after rounding to 2 decimal places, but might have slightly different representations when np.around to 2 decimal places. For example, is it possible a string representation of 1.52 can be represented by np.around(., 2) as 1.52000001 sometimes but  1.51999999 some other times?</p>

<p>My question is what is a better and more efficient way.</p>