diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index d8135dbf3f08d..e11c296783476 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -153,11 +153,23 @@ class providing the base-class of operations. transform : Apply function column-by-column to the GroupBy object. Series.apply : Apply a function to a Series. DataFrame.apply : Apply a function to each row or column of a DataFrame. + + Notes + ----- + In the current implementation `apply` calls `func` twice on the + first group to decide whether it can take a fast or slow code + path. This can lead to unexpected behavior if `func` has + side-effects, as they will take effect twice for the first + group. + + Examples + -------- + {examples} """, "dataframe_examples": """ >>> df = pd.DataFrame({'A': 'a a b'.split(), - 'B': [1,2,3], - 'C': [4,6, 5]}) + ... 'B': [1,2,3], + ... 'C': [4,6, 5]}) >>> g = df.groupby('A') Notice that ``g`` has two groups, ``a`` and ``b``. @@ -192,8 +204,7 @@ class providing the base-class of operations. A a 5 b 2 - dtype: int64 - """, + dtype: int64""", "series_examples": """ >>> s = pd.Series([0, 1, 2], index='a a b'.split()) >>> g = s.groupby(s.index) @@ -206,9 +217,9 @@ class providing the base-class of operations. each group together into a new Series: >>> g.apply(lambda x: x*2 if x.name == 'b' else x/2) - 0 0.0 - 1 0.5 - 2 4.0 + a 0.0 + a 0.5 + b 4.0 dtype: float64 Example 2: The function passed to `apply` takes a Series as @@ -219,20 +230,7 @@ class providing the base-class of operations. >>> g.apply(lambda x: x.max() - x.min()) a 1 b 0 - dtype: int64 - - Notes - ----- - In the current implementation `apply` calls `func` twice on the - first group to decide whether it can take a fast or slow code - path. This can lead to unexpected behavior if `func` has - side-effects, as they will take effect twice for the first - group. - - Examples - -------- - {examples} - """, + dtype: int64""", } _groupby_agg_method_template = """