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
File details
Details for the file pandas_accumulate-0.1.0.tar.gz
.
File metadata
- Download URL: pandas_accumulate-0.1.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 985ca6c1cf25dc8bd6ebdc745e706f03cb8cdeba4539edd871f09dc5387b1a22 |
|
MD5 | 2f08dbd3a72cc1f4f5ca9493dc98aa66 |
|
BLAKE2b-256 | 52a38d1eff98e5a4a5a6f347aec22f4454819077dca46076f086f643d8b0710b |
File details
Details for the file pandas_accumulate-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pandas_accumulate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6a84d1a2f08b9cb07a42124e46cccc93350fe1542637d6fad607d1b4c7dd33e |
|
MD5 | 0ff1b43e192348eb0dd3a2243bb5aee5 |
|
BLAKE2b-256 | 225e178709cce4570bd19a0165ab7b1fa56eb859ab84d627d01776f00c646cd9 |