@@ -341,6 +341,10 @@ class providing the base-class of operations.
341341-------
342342Series or DataFrame
343343 Computed {fname} of values within each group.
344+
345+ Examples
346+ --------
347+ {example}
344348"""
345349
346350_pipe_template = """
@@ -2550,7 +2554,46 @@ def size(self) -> DataFrame | Series:
25502554 return result
25512555
25522556 @final
2553- @doc (_groupby_agg_method_template , fname = "sum" , no = False , mc = 0 )
2557+ @doc (
2558+ _groupby_agg_method_template ,
2559+ fname = "sum" ,
2560+ no = False ,
2561+ mc = 0 ,
2562+ example = dedent (
2563+ """\
2564+ For SeriesGroupBy:
2565+
2566+ >>> lst = ['a', 'a', 'b', 'b']
2567+ >>> ser = pd.Series([1, 2, 3, 4], index=lst)
2568+ >>> ser
2569+ a 1
2570+ a 2
2571+ b 3
2572+ b 4
2573+ dtype: int64
2574+ >>> ser.groupby(level=0).sum()
2575+ a 3
2576+ b 7
2577+ dtype: int64
2578+
2579+ For DataFrameGroupBy:
2580+
2581+ >>> data = [[1, 8, 2], [1, 2, 5], [2, 5, 8], [2, 6, 9]]
2582+ >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
2583+ ... index=["tiger", "leopard", "cheetah", "lion"])
2584+ >>> df
2585+ a b c
2586+ tiger 1 8 2
2587+ leopard 1 2 5
2588+ cheetah 2 5 8
2589+ lion 2 6 9
2590+ >>> df.groupby("a").sum()
2591+ b c
2592+ a
2593+ 1 10 7
2594+ 2 11 17"""
2595+ ),
2596+ )
25542597 def sum (
25552598 self ,
25562599 numeric_only : bool = False ,
@@ -2580,14 +2623,92 @@ def sum(
25802623 return self ._reindex_output (result , fill_value = 0 )
25812624
25822625 @final
2583- @doc (_groupby_agg_method_template , fname = "prod" , no = False , mc = 0 )
2626+ @doc (
2627+ _groupby_agg_method_template ,
2628+ fname = "prod" ,
2629+ no = False ,
2630+ mc = 0 ,
2631+ example = dedent (
2632+ """\
2633+ For SeriesGroupBy:
2634+
2635+ >>> lst = ['a', 'a', 'b', 'b']
2636+ >>> ser = pd.Series([1, 2, 3, 4], index=lst)
2637+ >>> ser
2638+ a 1
2639+ a 2
2640+ b 3
2641+ b 4
2642+ dtype: int64
2643+ >>> ser.groupby(level=0).prod()
2644+ a 2
2645+ b 12
2646+ dtype: int64
2647+
2648+ For DataFrameGroupBy:
2649+
2650+ >>> data = [[1, 8, 2], [1, 2, 5], [2, 5, 8], [2, 6, 9]]
2651+ >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
2652+ ... index=["tiger", "leopard", "cheetah", "lion"])
2653+ >>> df
2654+ a b c
2655+ tiger 1 8 2
2656+ leopard 1 2 5
2657+ cheetah 2 5 8
2658+ lion 2 6 9
2659+ >>> df.groupby("a").prod()
2660+ b c
2661+ a
2662+ 1 16 10
2663+ 2 30 72"""
2664+ ),
2665+ )
25842666 def prod (self , numeric_only : bool = False , min_count : int = 0 ):
25852667 return self ._agg_general (
25862668 numeric_only = numeric_only , min_count = min_count , alias = "prod" , npfunc = np .prod
25872669 )
25882670
25892671 @final
2590- @doc (_groupby_agg_method_template , fname = "min" , no = False , mc = - 1 )
2672+ @doc (
2673+ _groupby_agg_method_template ,
2674+ fname = "min" ,
2675+ no = False ,
2676+ mc = - 1 ,
2677+ example = dedent (
2678+ """\
2679+ For SeriesGroupBy:
2680+
2681+ >>> lst = ['a', 'a', 'b', 'b']
2682+ >>> ser = pd.Series([1, 2, 3, 4], index=lst)
2683+ >>> ser
2684+ a 1
2685+ a 2
2686+ b 3
2687+ b 4
2688+ dtype: int64
2689+ >>> ser.groupby(level=0).min()
2690+ a 1
2691+ b 3
2692+ dtype: int64
2693+
2694+ For DataFrameGroupBy:
2695+
2696+ >>> data = [[1, 8, 2], [1, 2, 5], [2, 5, 8], [2, 6, 9]]
2697+ >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
2698+ ... index=["tiger", "leopard", "cheetah", "lion"])
2699+ >>> df
2700+ a b c
2701+ tiger 1 8 2
2702+ leopard 1 2 5
2703+ cheetah 2 5 8
2704+ lion 2 6 9
2705+ >>> df.groupby("a").min()
2706+ b c
2707+ a
2708+ 1 2 2
2709+ 2 5 8"""
2710+ ),
2711+ )
25912712 def min (
25922713 self ,
25932714 numeric_only : bool = False ,
@@ -2608,7 +2729,46 @@ def min(
26082729 )
26092730
26102731 @final
2611- @doc (_groupby_agg_method_template , fname = "max" , no = False , mc = - 1 )
2732+ @doc (
2733+ _groupby_agg_method_template ,
2734+ fname = "max" ,
2735+ no = False ,
2736+ mc = - 1 ,
2737+ example = dedent (
2738+ """\
2739+ For SeriesGroupBy:
2740+
2741+ >>> lst = ['a', 'a', 'b', 'b']
2742+ >>> ser = pd.Series([1, 2, 3, 4], index=lst)
2743+ >>> ser
2744+ a 1
2745+ a 2
2746+ b 3
2747+ b 4
2748+ dtype: int64
2749+ >>> ser.groupby(level=0).max()
2750+ a 2
2751+ b 4
2752+ dtype: int64
2753+
2754+ For DataFrameGroupBy:
2755+
2756+ >>> data = [[1, 8, 2], [1, 2, 5], [2, 5, 8], [2, 6, 9]]
2757+ >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
2758+ ... index=["tiger", "leopard", "cheetah", "lion"])
2759+ >>> df
2760+ a b c
2761+ tiger 1 8 2
2762+ leopard 1 2 5
2763+ cheetah 2 5 8
2764+ lion 2 6 9
2765+ >>> df.groupby("a").max()
2766+ b c
2767+ a
2768+ 1 8 5
2769+ 2 6 9"""
2770+ ),
2771+ )
26122772 def max (
26132773 self ,
26142774 numeric_only : bool = False ,
0 commit comments