'Fill in dataframe column into separate percentiles

I have a large dataframe that looks something like this:

ID   Fruit       Percentiles
001  Apple          0
002  Pear           0
003  Banana         0
004  Kiwi           0
005  Orange         0
006  Pineapple      0
...
...
039  Peach          0
040  Grapes         0

I want to create 40 different Percentiles (the data frame is already sorted, so I just need a way to fill the "Percentile" column)

The final Dataframe should look like this:

ID   Fruit       Percentile
001  Apple          1
002  Pear           1
003  Banana         2
004  Kiwi           2
005  Orange         3
006  Pineapple      3
...
...
039  Peach          40
040  Grapes         40

I have tried to create a loop which does something like this:

df.Category[0:int(df.size[0]*0.05)] = 1
df.Category[int(df.size[0]*0.05):int(df.size[0]*0.10)+1] = 2
...
...
df.Category[int(df.size[0]*0.95):int(df.size[0])+1] = 20


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source