pandas.core.window.rolling.Window.sum
- Window.sum(numeric_only=False, **kwargs)[source]
-
Calculate the rolling weighted window sum.
- Parameters:
-
- numeric_only:bool, default False
-
Include only float, int, boolean columns.
New in version 1.5.0.
- **kwargs
-
Keyword arguments to configure the
SciPyweighted window type.
- Returns:
-
- Series or DataFrame
-
Return type is the same as the original object with
np.float64dtype.
See also
pandas.Series.rolling-
Calling rolling with Series data.
pandas.DataFrame.rolling-
Calling rolling with DataFrames.
pandas.Series.sum-
Aggregating sum for Series.
pandas.DataFrame.sum-
Aggregating sum for DataFrame.
Examples
>>> ser = pd.Series([0, 1, 5, 2, 8])
To get an instance of
Windowwe need to pass the parameter win_type.>>> type(ser.rolling(2, win_type='gaussian')) <class 'pandas.core.window.rolling.Window'>
In order to use the SciPy Gaussian window we need to provide the parameters M and std. The parameter M corresponds to 2 in our example. We pass the second parameter std as a parameter of the following method (sum in this case):
>>> ser.rolling(2, win_type='gaussian').sum(std=3) 0 NaN 1 0.986207 2 5.917243 3 6.903450 4 9.862071 dtype: float64
© 2008–2022, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.2.2/reference/api/pandas.core.window.rolling.Window.sum.html