Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: percentile ranks #5971

Closed
MichaelWS opened this issue Jan 16, 2014 · 4 comments · Fixed by #5978
Closed

Suggestion: percentile ranks #5971

MichaelWS opened this issue Jan 16, 2014 · 4 comments · Fixed by #5978
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Enhancement Groupby Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@MichaelWS
Copy link
Contributor

I realize I am computing percentile ranks constantly in my code.

df["pct_rank"] = df["field"].groupby("date").transform(lambda x: x.rank(ascending=False) / float(x.count()))

Would anyone have any use for a function that is computed in cython for this?

if so, would people prefer to it to be a separate function or an option in rank?

@jreback
Copy link
Contributor

jreback commented Jan 16, 2014

can you do this with cumcount and size?

@MichaelWS
Copy link
Contributor Author

Thanks. You are right.

You could do it by this
grouped = df["field"].groupby("date")
df["pct_rank"] =grouped.rank() / grouped.size()

though its a 15% speedup to put it into the rank() function.

@jreback
Copy link
Contributor

jreback commented Jan 16, 2014

true....you could add a kw arg to the groupby rank..easy enough

and get experience with cython...always good!

go for it

maybe percentage=False as a kw

@MichaelWS
Copy link
Contributor Author

Thanks. I added that as a keyword for a series.

groupby("date").rank(percentage=True) works as intended for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Enhancement Groupby Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants