Run-length encoding for data analysis in Python
Project description
python-rle
Run-length encoding (wikipedia link) for data analysis in Python. Install with pip install python-rle
. No dependencies required other than tqdm
for visualizing a progress bar.
Usage
Encode any iterable (tuples, lists, pd.Series etc.) with rle.encode
.
# rle.encode(iterable) returns (values, counts)
>>> import rle
>>> rle.encode((10, 10, 10, 20, 20, 20, 30, 30, 30))
([10, 20, 30], [3, 3, 3])
Decode (values, counts) back into a sequence with rle.decode
.
>>> rle.decode([10, 20, 30], [3, 3, 3])
[10, 10, 10, 20, 20, 20, 30, 30, 30]
Set progress_bar
== True
for long sequences :
Motivation
Base R contains a simple rle
function that "computes the lengths and values of runs of equal values in a vector", as described by its docstring. I found it useful for calculating streaks in collected data, and is especially wonderful for compiling and summarizing categorical data that describes status over time. Hence this little utility.
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
Hashes for python_rle-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52a086dad15bf98e1242a45f70ff0d7e0a0e9cd0a8bcc91ed36404c4b713c654 |
|
MD5 | dec0b4386cdab7b1a59c431244984fe3 |
|
BLAKE2b-256 | a4cafc4dc810c892f8284d41046b60105fea56a7689a5b31e55e0b47c6aff971 |