How to check the percentile of each row based on a column in pandas?
<p>I have a dataset with a <code>id</code> column for each event and a <code>value</code> column (among other columns) in a dataframe. What I want to do is categorize each <code>id</code> based on whether it is on the 90th percentile, 50th percentile, 25th percentile etc. of the frequency distribution of the value colum.</p>

<p>Example,</p>

<pre><code>id      value
1       12.5
2       4.6
....
</code></pre>

<p>So, I'd add another column <code>category</code> to it depending upon the what percentile of the value column it falls in. How do I do that?</p>

<p>You're looking for the <code>quantile</code> method. For instance, assigning to <code>0.0, 0.25, 0.5, 0.75</code> quantiles could be done this way:</p>

<pre><code>df['quantile'] = 0.0

for q in [0.25, 0.5, 0.75]:
    df.loc[df['value'] &gt;= df['value'].quantile(q), 'quantile'] = q
</code></pre>

python pandas statistics