@@ -183,7 +183,19 @@ def aggregate(self, func, *args, **kwargs):
183
183
create_section_header ("Returns" ),
184
184
template_returns ,
185
185
create_section_header ("See Also" ),
186
- template_see_also [:- 1 ],
186
+ template_see_also ,
187
+ create_section_header ("Examples" ),
188
+ dedent (
189
+ """\
190
+ >>> ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
191
+ >>> ser.expanding().count()
192
+ a 1.0
193
+ b 2.0
194
+ c 3.0
195
+ d 4.0
196
+ dtype: float64
197
+ """
198
+ ),
187
199
window_method = "expanding" ,
188
200
aggregation_description = "count of non NaN observations" ,
189
201
agg_method = "count" ,
@@ -198,7 +210,19 @@ def count(self, numeric_only: bool = False):
198
210
create_section_header ("Returns" ),
199
211
template_returns ,
200
212
create_section_header ("See Also" ),
201
- template_see_also [:- 1 ],
213
+ template_see_also ,
214
+ create_section_header ("Examples" ),
215
+ dedent (
216
+ """\
217
+ >>> ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
218
+ >>> ser.expanding().apply(lambda s: s.max() - 2 * s.min())
219
+ a -1.0
220
+ b 0.0
221
+ c 1.0
222
+ d 2.0
223
+ dtype: float64
224
+ """
225
+ ),
202
226
window_method = "expanding" ,
203
227
aggregation_description = "custom aggregation function" ,
204
228
agg_method = "apply" ,
@@ -231,7 +255,19 @@ def apply(
231
255
create_section_header ("See Also" ),
232
256
template_see_also ,
233
257
create_section_header ("Notes" ),
234
- numba_notes [:- 1 ],
258
+ numba_notes ,
259
+ create_section_header ("Examples" ),
260
+ dedent (
261
+ """\
262
+ >>> ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
263
+ >>> ser.expanding().sum()
264
+ a 1.0
265
+ b 3.0
266
+ c 6.0
267
+ d 10.0
268
+ dtype: float64
269
+ """
270
+ ),
235
271
window_method = "expanding" ,
236
272
aggregation_description = "sum" ,
237
273
agg_method = "sum" ,
@@ -258,7 +294,19 @@ def sum(
258
294
create_section_header ("See Also" ),
259
295
template_see_also ,
260
296
create_section_header ("Notes" ),
261
- numba_notes [:- 1 ],
297
+ numba_notes ,
298
+ create_section_header ("Examples" ),
299
+ dedent (
300
+ """\
301
+ >>> ser = pd.Series([3, 2, 1, 4], index=['a', 'b', 'c', 'd'])
302
+ >>> ser.expanding().max()
303
+ a 3.0
304
+ b 3.0
305
+ c 3.0
306
+ d 4.0
307
+ dtype: float64
308
+ """
309
+ ),
262
310
window_method = "expanding" ,
263
311
aggregation_description = "maximum" ,
264
312
agg_method = "max" ,
@@ -285,7 +333,19 @@ def max(
285
333
create_section_header ("See Also" ),
286
334
template_see_also ,
287
335
create_section_header ("Notes" ),
288
- numba_notes [:- 1 ],
336
+ numba_notes ,
337
+ create_section_header ("Examples" ),
338
+ dedent (
339
+ """\
340
+ >>> ser = pd.Series([2, 3, 4, 1], index=['a', 'b', 'c', 'd'])
341
+ >>> ser.expanding().min()
342
+ a 2.0
343
+ b 2.0
344
+ c 2.0
345
+ d 1.0
346
+ dtype: float64
347
+ """
348
+ ),
289
349
window_method = "expanding" ,
290
350
aggregation_description = "minimum" ,
291
351
agg_method = "min" ,
@@ -312,7 +372,19 @@ def min(
312
372
create_section_header ("See Also" ),
313
373
template_see_also ,
314
374
create_section_header ("Notes" ),
315
- numba_notes [:- 1 ],
375
+ numba_notes ,
376
+ create_section_header ("Examples" ),
377
+ dedent (
378
+ """\
379
+ >>> ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
380
+ >>> ser.expanding().mean()
381
+ a 1.0
382
+ b 1.5
383
+ c 2.0
384
+ d 2.5
385
+ dtype: float64
386
+ """
387
+ ),
316
388
window_method = "expanding" ,
317
389
aggregation_description = "mean" ,
318
390
agg_method = "mean" ,
@@ -339,7 +411,19 @@ def mean(
339
411
create_section_header ("See Also" ),
340
412
template_see_also ,
341
413
create_section_header ("Notes" ),
342
- numba_notes [:- 1 ],
414
+ numba_notes ,
415
+ create_section_header ("Examples" ),
416
+ dedent (
417
+ """\
418
+ >>> ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
419
+ >>> ser.expanding().median()
420
+ a 1.0
421
+ b 1.5
422
+ c 2.0
423
+ d 2.5
424
+ dtype: float64
425
+ """
426
+ ),
343
427
window_method = "expanding" ,
344
428
aggregation_description = "median" ,
345
429
agg_method = "median" ,
@@ -523,7 +607,20 @@ def sem(self, ddof: int = 1, numeric_only: bool = False):
523
607
"scipy.stats.skew : Third moment of a probability density.\n " ,
524
608
template_see_also ,
525
609
create_section_header ("Notes" ),
526
- "A minimum of three periods is required for the rolling calculation.\n " ,
610
+ "A minimum of three periods is required for the rolling calculation.\n \n " ,
611
+ create_section_header ("Examples" ),
612
+ dedent (
613
+ """\
614
+ >>> ser = pd.Series([-1, 0, 2, -1, 2], index=['a', 'b', 'c', 'd', 'e'])
615
+ >>> ser.expanding().skew()
616
+ a NaN
617
+ b NaN
618
+ c 0.935220
619
+ d 1.414214
620
+ e 0.315356
621
+ dtype: float64
622
+ """
623
+ ),
527
624
window_method = "expanding" ,
528
625
aggregation_description = "unbiased skewness" ,
529
626
agg_method = "skew" ,
@@ -597,7 +694,21 @@ def kurt(self, numeric_only: bool = False):
597
694
create_section_header ("Returns" ),
598
695
template_returns ,
599
696
create_section_header ("See Also" ),
600
- template_see_also [:- 1 ],
697
+ template_see_also ,
698
+ create_section_header ("Examples" ),
699
+ dedent (
700
+ """\
701
+ >>> ser = pd.Series([1, 2, 3, 4, 5, 6], index=['a', 'b', 'c', 'd', 'e', 'f'])
702
+ >>> ser.expanding(min_periods=4).quantile(.25)
703
+ a NaN
704
+ b NaN
705
+ c NaN
706
+ d 1.75
707
+ e 2.00
708
+ f 2.25
709
+ dtype: float64
710
+ """
711
+ ),
601
712
window_method = "expanding" ,
602
713
aggregation_description = "quantile" ,
603
714
agg_method = "quantile" ,
@@ -714,7 +825,20 @@ def rank(
714
825
create_section_header ("Returns" ),
715
826
template_returns ,
716
827
create_section_header ("See Also" ),
717
- template_see_also [:- 1 ],
828
+ template_see_also ,
829
+ create_section_header ("Examples" ),
830
+ dedent (
831
+ """\
832
+ >>> ser1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
833
+ >>> ser2 = pd.Series([10, 11, 13, 16], index=['a', 'b', 'c', 'd'])
834
+ >>> ser1.expanding().cov(ser2)
835
+ a NaN
836
+ b 0.500000
837
+ c 1.500000
838
+ d 3.333333
839
+ dtype: float64
840
+ """
841
+ ),
718
842
window_method = "expanding" ,
719
843
aggregation_description = "sample covariance" ,
720
844
agg_method = "cov" ,
@@ -782,9 +906,22 @@ def cov(
782
906
columns on the second level.
783
907
784
908
In the case of missing elements, only complete pairwise observations
785
- will be used.
909
+ will be used.\n
786
910
"""
787
- ).replace ("\n " , "" , 1 ),
911
+ ),
912
+ create_section_header ("Examples" ),
913
+ dedent (
914
+ """\
915
+ >>> ser1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
916
+ >>> ser2 = pd.Series([10, 11, 13, 16], index=['a', 'b', 'c', 'd'])
917
+ >>> ser1.expanding().corr(ser2)
918
+ a NaN
919
+ b 1.000000
920
+ c 0.981981
921
+ d 0.975900
922
+ dtype: float64
923
+ """
924
+ ),
788
925
window_method = "expanding" ,
789
926
aggregation_description = "correlation" ,
790
927
agg_method = "corr" ,
0 commit comments