Skip to content

Commit 002796a

Browse files
othersideoflearningTomAugspurger
authored andcommitted
DOC: Update the pandas.core.window.x.sum docstring (#20272)
1 parent c124e47 commit 002796a

File tree

1 file changed

+73
-4
lines changed

1 file changed

+73
-4
lines changed

pandas/core/window.py

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,79 @@ def aggregate(self, arg, *args, **kwargs):
320320
agg = aggregate
321321

322322
_shared_docs['sum'] = dedent("""
323-
%(name)s sum""")
323+
Calculate %(name)s sum of given DataFrame or Series.
324+
325+
Parameters
326+
----------
327+
*args, **kwargs
328+
For compatibility with other %(name)s methods. Has no effect
329+
on the computed value.
330+
331+
Returns
332+
-------
333+
Series or DataFrame
334+
Same type as the input, with the same index, containing the
335+
%(name)s sum.
336+
337+
See Also
338+
--------
339+
Series.sum : Reducing sum for Series.
340+
DataFrame.sum : Reducing sum for DataFrame.
341+
342+
Examples
343+
--------
344+
>>> s = pd.Series([1, 2, 3, 4, 5])
345+
>>> s
346+
0 1
347+
1 2
348+
2 3
349+
3 4
350+
4 5
351+
dtype: int64
352+
353+
>>> s.rolling(3).sum()
354+
0 NaN
355+
1 NaN
356+
2 6.0
357+
3 9.0
358+
4 12.0
359+
dtype: float64
360+
361+
>>> s.expanding(3).sum()
362+
0 NaN
363+
1 NaN
364+
2 6.0
365+
3 10.0
366+
4 15.0
367+
dtype: float64
368+
369+
>>> s.rolling(3, center=True).sum()
370+
0 NaN
371+
1 6.0
372+
2 9.0
373+
3 12.0
374+
4 NaN
375+
dtype: float64
376+
377+
For DataFrame, each %(name)s sum is computed column-wise.
378+
379+
>>> df = pd.DataFrame({"A": s, "B": s ** 2})
380+
>>> df
381+
A B
382+
0 1 1
383+
1 2 4
384+
2 3 9
385+
3 4 16
386+
4 5 25
387+
388+
>>> df.rolling(3).sum()
389+
A B
390+
0 NaN NaN
391+
1 NaN NaN
392+
2 6.0 14.0
393+
3 9.0 29.0
394+
4 12.0 50.0
395+
""")
324396

325397
_shared_docs['mean'] = dedent("""
326398
%(name)s mean""")
@@ -640,7 +712,6 @@ def aggregate(self, arg, *args, **kwargs):
640712
agg = aggregate
641713

642714
@Substitution(name='window')
643-
@Appender(_doc_template)
644715
@Appender(_shared_docs['sum'])
645716
def sum(self, *args, **kwargs):
646717
nv.validate_window_func('sum', args, kwargs)
@@ -1326,7 +1397,6 @@ def apply(self, func, args=(), kwargs={}):
13261397
return super(Rolling, self).apply(func, args=args, kwargs=kwargs)
13271398

13281399
@Substitution(name='rolling')
1329-
@Appender(_doc_template)
13301400
@Appender(_shared_docs['sum'])
13311401
def sum(self, *args, **kwargs):
13321402
nv.validate_rolling_func('sum', args, kwargs)
@@ -1588,7 +1658,6 @@ def apply(self, func, args=(), kwargs={}):
15881658
return super(Expanding, self).apply(func, args=args, kwargs=kwargs)
15891659

15901660
@Substitution(name='expanding')
1591-
@Appender(_doc_template)
15921661
@Appender(_shared_docs['sum'])
15931662
def sum(self, *args, **kwargs):
15941663
nv.validate_expanding_func('sum', args, kwargs)

0 commit comments

Comments
 (0)