@@ -153,11 +153,23 @@ class providing the base-class of operations.
153
153
transform : Apply function column-by-column to the GroupBy object.
154
154
Series.apply : Apply a function to a Series.
155
155
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}
156
168
""" ,
157
169
"dataframe_examples" : """
158
170
>>> 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]})
161
173
>>> g = df.groupby('A')
162
174
163
175
Notice that ``g`` has two groups, ``a`` and ``b``.
@@ -192,8 +204,7 @@ class providing the base-class of operations.
192
204
A
193
205
a 5
194
206
b 2
195
- dtype: int64
196
- """ ,
207
+ dtype: int64""" ,
197
208
"series_examples" : """
198
209
>>> s = pd.Series([0, 1, 2], index='a a b'.split())
199
210
>>> g = s.groupby(s.index)
@@ -206,9 +217,9 @@ class providing the base-class of operations.
206
217
each group together into a new Series:
207
218
208
219
>>> 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
212
223
dtype: float64
213
224
214
225
Example 2: The function passed to `apply` takes a Series as
@@ -219,20 +230,7 @@ class providing the base-class of operations.
219
230
>>> g.apply(lambda x: x.max() - x.min())
220
231
a 1
221
232
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""" ,
236
234
}
237
235
238
236
_groupby_agg_method_template = """
0 commit comments