I have many scores in the column of an object named example
. I want to split these scores into deciles and assign the corresponding decile interval to each row. I tried the following:
import random
import pandas as pd
random.seed(420) #blazeit
example = pd.DataFrame({"Score":[random.randrange(350, 1000) for i in range(1000)]})
example["Decile"] = pd.qcut(example["Score"], 10, labels=False) + 1 # Deciles as integer from 1 to 10
example["Decile_interval"] = pd.qcut(example["Score"], 10) # Decile as interval
This gives me the deciles I'm looking for. However, I would like the deciles in example["Decile_interval"]
to be integers, not floats. I tried precision=0
but it just shows .0
at the end of each number.
How can I transform the floats in the intervals to integers?
EDIT: As pointet out by @ALollz, doing this will change the decile distribution. However, I am doing this for presentation purposes, so I am not worried by this. Props to @JuanC for realizing this and posting one solution.