@@ -2641,7 +2641,6 @@ def cumcount(self, ascending: bool = True):
2641
2641
2642
2642
@final
2643
2643
@Substitution (name = "groupby" )
2644
- @Appender (_common_see_also )
2645
2644
def rank (
2646
2645
self ,
2647
2646
method : str = "average" ,
@@ -2675,6 +2674,49 @@ def rank(
2675
2674
Returns
2676
2675
-------
2677
2676
DataFrame with ranking of values within each group
2677
+
2678
+ See Also
2679
+ --------
2680
+ Series.groupby : Apply a function groupby to a Series.
2681
+ DataFrame.groupby : Apply a function groupby
2682
+ to each row or column of a DataFrame.
2683
+ Series.rank : Apply a function rank to a Series.
2684
+ DataFrame.rank : Apply a function rank
2685
+ to each row or column of a DataFrame.
2686
+
2687
+ Examples
2688
+ --------
2689
+ >>> df = pd.DataFrame({'group': ['a', 'a', 'a', 'b', 'a', 'b', 'b', 'b', 'b', 'a'],
2690
+ ... 'value': [.2, .4, .2, 0.01, .3, .11, .21, .4, .01, 0.2]})
2691
+ >>> df
2692
+ group value
2693
+ 0 a 0.20
2694
+ 1 a 0.40
2695
+ 2 a 0.20
2696
+ 3 b 0.01
2697
+ 4 a 0.30
2698
+ 5 b 0.11
2699
+ 6 b 0.21
2700
+ 7 b 0.40
2701
+ 8 b 0.01
2702
+ 9 a 0.20
2703
+ >>> df['average_rank'] = df.groupby('group')['value'].rank('average')
2704
+ >>> df['min_rank'] = df.groupby('group')['value'].rank('min')
2705
+ >>> df['max_rank'] = df.groupby('group')['value'].rank('max')
2706
+ >>> df['dense_rank'] = df.groupby('group')['value'].rank('dense')
2707
+ >>> df['first_rank'] = df.groupby('group')['value'].rank('first')
2708
+ >>> df
2709
+ group value average_rank min_rank max_rank dense_rank first_rank
2710
+ 0 a 0.20 2.0 1.0 3.0 1.0 1.0
2711
+ 1 a 0.40 5.0 5.0 5.0 3.0 5.0
2712
+ 2 a 0.20 2.0 1.0 3.0 1.0 2.0
2713
+ 3 b 0.01 1.5 1.0 2.0 1.0 1.0
2714
+ 4 a 0.30 4.0 4.0 4.0 2.0 4.0
2715
+ 5 b 0.11 3.0 3.0 3.0 2.0 3.0
2716
+ 6 b 0.21 4.0 4.0 4.0 3.0 4.0
2717
+ 7 b 0.40 5.0 5.0 5.0 4.0 5.0
2718
+ 8 b 0.01 1.5 1.0 2.0 1.0 2.0
2719
+ 9 a 0.20 2.0 1.0 3.0 1.0 3.0
2678
2720
"""
2679
2721
if na_option not in {"keep" , "top" , "bottom" }:
2680
2722
msg = "na_option must be one of 'keep', 'top', or 'bottom'"
0 commit comments