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

similar to pandas.Series.rank() #3148

Open
ztsweet opened this issue Aug 19, 2021 · 1 comment
Open

similar to pandas.Series.rank() #3148

ztsweet opened this issue Aug 19, 2021 · 1 comment

Comments

@ztsweet
Copy link

ztsweet commented Aug 19, 2021

import pandas as pd
#
df = pd.DataFrame({
    'name1':['A', 'B','A', 'B', 'A','B'],
    'name2':['a','b','c','d','e','f'],
    'goal':[92,91,90,89,88,87]
})
def f(x):
    x['rank_num'] = x['goal'].rank(ascending=False)
    return x
df1 = df.groupby('name1').apply(lambda x:f(x)).sort_values(['name1', 'name2'])
print(df1)

`
  | name1 | name2 | goal | rank_num
-- | -- | -- | -- | --
A | a | 92 | 1.0
A | c | 90 | 2.0
A | e | 88 | 3.0
B | b | 91 | 1.0
B | d | 89 | 2.0
B | f | 87 | 3.0
`

@oleksiyskononenko
Copy link
Contributor

@samukweku Can we move the rank() implementation to this issue and close #3279?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants