4 examples of 'pandas cumsum' in Python

Every line of 'pandas cumsum' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
803def cum_sum(self, data_frame):
804 """Calculates the cumulative sum
806 Parameters
807 ----------
808 data_frame : DataFrame
809 contains time series
811 Returns
812 -------
813 DataFrame
814 """
815 return data_frame.cumsum()
13def cumsum_filter(values: pd.Series, thresholds: pd.Series, parallel=True):
14 """
15 cumsum filter based on Advances in Financial Machine Learning book by Marcos Lopez de Prado
16 :param values: series of values to apply the cumsum filter over
17 :param thresholds: series of thresholds for the values of the cumsum filter
18 :param parallel: run in multiprocessing mode for multiindex dataframes
19 :return events
20 """
21 if values.index.equals(thresholds.index) is False:
22 raise ValueError('values and thresholds have different index')
24 df = pd.concat([values.rename('value'), thresholds.rename('threshold')], axis=1)
26 if isinstance(df.index, pd.MultiIndex):
27 grpby = df.groupby(level='symbol', group_keys=False, sort=False)
28 if parallel:
29 with Pool(cpu_count()) as p:
30 ret_list = p.map(_cumsum_filter, [group for name, group in grpby])
32 return pd.concat(ret_list).index
33 else:
34 return grpby.apply(_cumsum_filter).index
35 else:
36 return _cumsum_filter(df).index
373def cumsum(a, endpoint=False):
374 """As numpy.cumsum for a 1d array a, but starts from 0. If endpoint is True, the result
375 will have one more element than the input, and the last element will be the sum of the
376 array. Otherwise (the default), it will have the same length as the array, and the last
377 element will be the sum of the first n-1 elements."""
378 res = np.concatenate([[0],np.cumsum(a)])
379 return res if endpoint else res[:-1]
234def cumsum_n(x, n):
235 for _ in range(n):
236 x = np.cumsum(x)
238 return x

Related snippets