Skip to content

Commit 794ced5

Browse files
authored
DOC: Add Notes and Examples back to GroupBy.apply docs template (#40207)
1 parent 169aa99 commit 794ced5

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

pandas/core/groupby/groupby.py

+19-21
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,23 @@ class providing the base-class of operations.
153153
transform : Apply function column-by-column to the GroupBy object.
154154
Series.apply : Apply a function to a Series.
155155
DataFrame.apply : Apply a function to each row or column of a DataFrame.
156+
157+
Notes
158+
-----
159+
In the current implementation `apply` calls `func` twice on the
160+
first group to decide whether it can take a fast or slow code
161+
path. This can lead to unexpected behavior if `func` has
162+
side-effects, as they will take effect twice for the first
163+
group.
164+
165+
Examples
166+
--------
167+
{examples}
156168
""",
157169
"dataframe_examples": """
158170
>>> df = pd.DataFrame({'A': 'a a b'.split(),
159-
'B': [1,2,3],
160-
'C': [4,6, 5]})
171+
... 'B': [1,2,3],
172+
... 'C': [4,6, 5]})
161173
>>> g = df.groupby('A')
162174
163175
Notice that ``g`` has two groups, ``a`` and ``b``.
@@ -192,8 +204,7 @@ class providing the base-class of operations.
192204
A
193205
a 5
194206
b 2
195-
dtype: int64
196-
""",
207+
dtype: int64""",
197208
"series_examples": """
198209
>>> s = pd.Series([0, 1, 2], index='a a b'.split())
199210
>>> g = s.groupby(s.index)
@@ -206,9 +217,9 @@ class providing the base-class of operations.
206217
each group together into a new Series:
207218
208219
>>> g.apply(lambda x: x*2 if x.name == 'b' else x/2)
209-
0 0.0
210-
1 0.5
211-
2 4.0
220+
a 0.0
221+
a 0.5
222+
b 4.0
212223
dtype: float64
213224
214225
Example 2: The function passed to `apply` takes a Series as
@@ -219,20 +230,7 @@ class providing the base-class of operations.
219230
>>> g.apply(lambda x: x.max() - x.min())
220231
a 1
221232
b 0
222-
dtype: int64
223-
224-
Notes
225-
-----
226-
In the current implementation `apply` calls `func` twice on the
227-
first group to decide whether it can take a fast or slow code
228-
path. This can lead to unexpected behavior if `func` has
229-
side-effects, as they will take effect twice for the first
230-
group.
231-
232-
Examples
233-
--------
234-
{examples}
235-
""",
233+
dtype: int64""",
236234
}
237235

238236
_groupby_agg_method_template = """

0 commit comments

Comments
 (0)