MCPcopy
hub / github.com/pandas-dev/pandas / sum

Method sum

pandas/core/window/rolling.py:1299–1355  ·  view source on GitHub ↗

Calculate the rolling weighted window sum. Parameters ---------- numeric_only : bool, default False Include only float, int, boolean columns. **kwargs Keyword arguments to configure the ``SciPy`` weighted window type. Return

(self, numeric_only: bool = False, **kwargs)

Source from the content-addressed store, hash-verified

1297 agg = aggregate
1298
1299 def sum(self, numeric_only: bool = False, **kwargs):
1300 """
1301 Calculate the rolling weighted window sum.
1302
1303 Parameters
1304 ----------
1305 numeric_only : bool, default False
1306 Include only float, int, boolean columns.
1307
1308 **kwargs
1309 Keyword arguments to configure the ``SciPy`` weighted window type.
1310
1311 Returns
1312 -------
1313 Series or DataFrame
1314 Return type is the same as the original object with ``np.float64`` dtype.
1315
1316 See Also
1317 --------
1318 Series.rolling : Calling rolling with Series data.
1319 DataFrame.rolling : Calling rolling with DataFrames.
1320 Series.sum : Aggregating sum for Series.
1321 DataFrame.sum : Aggregating sum for DataFrame.
1322
1323 Examples
1324 --------
1325 >>> ser = pd.Series([0, 1, 5, 2, 8])
1326
1327 To get an instance of :class:`~pandas.core.window.rolling.Window` we need
1328 to pass the parameter `win_type`.
1329
1330 >>> type(ser.rolling(2, win_type="gaussian"))
1331 <class 'pandas.api.typing.Window'>
1332
1333 In order to use the `SciPy` Gaussian window we need to provide the parameters
1334 `M` and `std`. The parameter `M` corresponds to 2 in our example.
1335 We pass the second parameter `std` as a parameter of the following method
1336 (`sum` in this case):
1337
1338 >>> ser.rolling(2, win_type="gaussian").sum(std=3)
1339 0 NaN
1340 1 0.986207
1341 2 5.917243
1342 3 6.903450
1343 4 9.862071
1344 dtype: float64
1345 """
1346 window_func = window_aggregations.roll_weighted_sum
1347 # error: Argument 1 to "_apply" of "Window" has incompatible type
1348 # "Callable[[ndarray, ndarray, int], ndarray]"; expected
1349 # "Callable[[ndarray, int, int], ndarray]"
1350 return self._apply(
1351 window_func, # type: ignore[arg-type]
1352 name="sum",
1353 numeric_only=numeric_only,
1354 **kwargs,
1355 )
1356

Callers 15

cat_coreFunction · 0.45
whereMethod · 0.45
unstackMethod · 0.45
check_setitem_lengthsFunction · 0.45
length_of_indexerFunction · 0.45
roll_applyFunction · 0.45
roll_tableFunction · 0.45
sumMethod · 0.45
from_dummiesFunction · 0.45
_normalizeFunction · 0.45
_make_selectorsMethod · 0.45
putmaskMethod · 0.45

Calls 1

_applyMethod · 0.95

Tested by

no test coverage detected