Pandas GroupBy Doesn't Persist After Applying Quantiles?
<p>I'm trying to get quantiles for two distinct groups in a Pandas df. I'm able to apply to quantiles function and get a table with grouped results, however, I can't seem to call the groupby attributes on the dataframe after doing so. Example:</p>

<pre><code>rand = np.random.RandomState(1)
df = pd.DataFrame({'A': ['foo', 'bar'] * 3,
                   'B': rand.randn(6),
                   'C': rand.randint(0, 20, 6)})
gb = df.groupby(['A'])
gb.groups
</code></pre>

<p>This returns something like:</p>

<pre><code>{'bar': [1, 3, 5], 'foo': [0, 2, 4]}
</code></pre>

<p>Then I apply the quantile function:</p>

<pre><code>q=gb.quantile(np.arange(0,1.1,.1))
</code></pre>

<p>When I print this df, it shows the two groups, but when I try to call them, it throws an error:</p>

<pre><code>q.group
AttributeError: 'DataFrame' object has no attribute 'group'
</code></pre>

<p>How can I call the groups in the quantile dataframe?</p>

<p>(First, note that your code is missing</p>

<pre><code>import numpy as np
import numpy.random as rand
</code></pre>

<p>or something like that. The second one is a bit annoying to guess.)</p>

<p>Your two lines </p>

<pre><code>gb = df.groupby(['A'])
q=gb.quantile(np.arange(0,1.1,.1))
</code></pre>

<p>Are equivalent to </p>

<pre><code>q=df.groupby(['A']).quantile(np.arange(0,1.1,.1))
</code></pre>

<p>In other words, <code>q</code> is already the <em>result</em> of applying the quantile on each group. The result you're looking for is <code>q</code> itself:</p>

<pre><code>&gt;&gt;&gt; q
                B     C
A                      
bar 0.0 -1.311556  13.0
    0.1 -1.188745  13.2
    0.2 -1.065935  13.4
    0.3 -0.943124  13.6
    0.4 -0.820313  13.8
    0.5 -0.697503  14.0
    0.6 -0.662497  14.4
    0.7 -0.627492  14.8
    0.8 -0.592486  15.2
    0.9 -0.557481  15.6
    1.0 -0.522475  16.0
foo 0.0  0.032946   1.0
    0.1  0.051352   4.0
    0.2  0.069759   7.0
    0.3  0.088166  10.0
    0.4  0.106572  13.0
    0.5  0.124979  16.0
    0.6  0.388895  16.2
    0.7  0.652811  16.4
    0.8  0.916728  16.6
    0.9  1.180644  16.8
    1.0  1.444560  17.0
</code></pre>

python pandas