Issue
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?
Solution
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)]
Answered By - Binyamin Even
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.