I have a score
column in pandas dataframe df
for which I need to calculate percentiles from 0
to 100
inclusive with a step of 1
(0.00, 0.01, 0.02, 0.03, ..., 0.99, 1)
.
In R
, this is easily done with the following code:
perc <- quantile(df$score, probs = seq(0, 1, 0.01))
How to implement this in Python?
CodePudding user response:
You can use quantile
to get it in pandas as well.
For example:
df['score'].quantile(0.9)
To get all the quantiles from 0 to 1 I believe something like this should work:
perc = [df['score'].quantile(p) for p in np.arange(0,1,0.01)]