# pandas.core.window.Rolling.sum¶

Calculate rolling sum of given DataFrame or Series.

*args, **kwargs For compatibility with other rolling methods. Has no effect on the computed value. :return: Series or DataFrame

Same type as the input, with the same index, containing the rolling sum.

## Limitations¶

DataFrame/Series elements cannot be max/min float/integer. Otherwise SDC and Pandas results are different.

## Examples¶

Calculate rolling sum
import pandas as pd
from numba import njit

@njit
def series_rolling_sum():
series = pd.Series([4, 3, 5, 2, 6])  # Series of 4, 3, 5, 2, 6
out_series = series.rolling(3).sum()

return out_series  # Expect series of NaN, NaN, 12.0, 10.0, 13.0

print(series_rolling_sum())

$python ./series/rolling/series_rolling_sum.py 0 NaN 1 NaN 2 12.0 3 10.0 4 13.0 dtype: float64  Calculate rolling sum import pandas as pd from numba import njit @njit def df_rolling_sum(): df = pd.DataFrame({'A': [4, 3, 5, 2, 6], 'B': [-4, -3, -5, -2, -6]}) out_df = df.rolling(3).sum() # Expect DataFrame of # {'A': [NaN, NaN, 12.0, 10.0, 13.0], 'B': [NaN, NaN, -12.0, -10.0, -13.0]} return out_df print(df_rolling_sum())  $ python ./dataframe/rolling/dataframe_rolling_sum.py
A     B
0   NaN   NaN
1   NaN   NaN
2  12.0 -12.0
3  10.0 -10.0
4  13.0 -13.0


Series.rolling

Calling object with a Series.

DataFrame.rolling

Calling object with a DataFrame.

Series.sum

Similar method for Series.

DataFrame.sum

Similar method for DataFrame.