Accumulate Pandas series
Project description
pandas-accumulate
: accumulate values along Pandas series
This package provides one function that allows accumulating values along a
Pandas series very similar to cumsum
and cumprod
but allowing also other
operators like |
.
Usage examples
cumsum
Replicate cumsum:
>>> import operator
>>> import pandas as pd
>>> from pandas_accumulate import accumulate
>>> s = pd.Series([1, 2, 3])
>>> accumulate(s, operator.add)
0 1
1 3
2 6
dtype: int64
cumulative unique()
Collect the unique values cumulatively. Note: You need to pass an
initial
value for the accumulation in this example:
>>> s = pd.Series([1,2,1,3,2])
>>> def f(acc, v):
... return acc | {v}
>>> accumulate(s, f, initial=set())
0 {1}
1 {1, 2}
2 {1, 2}
3 {1, 2, 3}
4 {1, 2, 3}
dtype: object
cumulative nunique()
If you're interested only in the number of unique values, just call len
at
the end:
>>> accumulate(s, f, initial=set()).map(len)
0 1
1 2
2 2
3 3
4 3
dtype: int64
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for pandas_accumulate-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6a84d1a2f08b9cb07a42124e46cccc93350fe1542637d6fad607d1b4c7dd33e |
|
MD5 | 0ff1b43e192348eb0dd3a2243bb5aee5 |
|
BLAKE2b-256 | 225e178709cce4570bd19a0165ab7b1fa56eb859ab84d627d01776f00c646cd9 |