Categorize data into n category with same interval size in python
<p>Assume I want to categorize data below in 12 category:</p>

<pre><code>   no.     grades
    0      9.08
    1      8.31
    2      7.42
    3      7.42
    4      7.42
    5      7.46
    6      9.67
    7     11.77
    8      8.81
    9      6.44
    10     9.40
    11     9.06
    12    10.52
    13     6.19
    14     5.04
    15     5.04
    16     9.44
    17     5.87
    18     2.67
    19     6.99
    20     9.08
    21     6.64
    22     4.83
    23     4.47
    24     6.61
    25     6.61
    26     7.42
    27     6.42
    28    10.00
    29     9.11
</code></pre>

<p>It is possible to do it  with something like this:</p>

<pre><code>df.a[df.a &lt;= 1 and df.a&gt;0] = 1
df.a[df.a &lt;= 2 and df.a&gt;1] = 2
.
.
.
df.a[df.a &lt;= 12 and df.a&gt;11] = 12
</code></pre>

<p>Is there any other way to categorize item to categories with constant and equal intervals?</p>

<p>P.S:</p>

<p>my data is here and I want to categorize its grades column:</p>

<pre><code>     psechoice  hscath  grades  faminc  famsiz  parcoll  female  black
0            1       0    9.08   62.50       5        0       0      0
1            1       0    8.31   42.50       4        0       1      0
2            1       0    7.42   62.50       4        0       1      0
3            1       0    7.42   62.50       4        0       1      0
4            1       0    7.42   62.50       4        0       1      0
5            1       0    7.46   12.50       2        0       1      0
6            1       0    9.67   30.00       5        0       0      0
7            0       0   11.77   42.50       4        0       0      0
8            1       0    8.81   17.50       3        0       1      0
9            1       0    6.44   42.50       6        0       0      0
10           1       0    9.40   30.00       5        1       0      0
11           1       0    9.06   62.50       6        0       0      0
12           0       0   10.52   62.50       3        0       0      0
13           1       0    6.19   62.50       2        0       1      0
14           1       0    5.04   42.50       6        0       1      0
15           1       0    5.04   42.50       6        0       1      0
16           0       0    9.44   22.50       2        0       1      0
17           1       1    5.87   87.50       5        1       0      0
18           1       1    2.67   62.50       4        0       0      0
19           1       1    6.99   42.50       5        0       0      0
20           1       1    9.08  150.00       4        1       1      0
21           1       0    6.64   42.50       9        0       1      0
22           1       1    4.83    0.50       4        1       0      0
23           1       1    4.47   62.50       3        0       1      0
24           1       1    6.61   87.50       6        1       0      0
25           1       1    6.61   87.50       6        1       0      0
26           1       1    7.42   42.50       4        1       0      0
27           1       1    6.42   87.50       5        1       0      0
28           1       0   10.00    8.75       4        1       1      0
29           1       0    9.11   22.50       3        0       0      1
</code></pre>