Skip to content

Get lengths and values of runs of equal values in a pandas Series, or vice versa

License

Notifications You must be signed in to change notification settings

darshanbaral/pdrle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pdrle

Installation

pip install pdrle

Usage

import pdrle
import pandas

x = pandas.Series(["a", "a", "b", "b", "a", "a", "a", "c"])

rle = pdrle.encode(x)
rle
#   vals  runs
# 0    a     2
# 1    b     2
# 2    a     3
# 3    c     1

y = pdrle.decode(rle.vals, rle.runs)
y
# 0    a
# 1    a
# 2    b
# 3    b
# 4    a
# 5    a
# 6    a
# 7    c
# dtype: object

pandas.concat({"x": x, "id": pdrle.get_id(x)}, axis=1)
#    x  id
# 0  a   0
# 1  a   0
# 2  b   1
# 3  b   1
# 4  a   2
# 5  a   2
# 6  a   2
# 7  c   3

pandas.concat({"x": x, "sn": pdrle.get_sn(x)}, axis=1)
#    x  sn
# 0  a   0
# 1  a   1
# 2  b   0
# 3  b   1
# 4  a   0
# 5  a   1
# 6  a   2
# 7  c   0

About

Get lengths and values of runs of equal values in a pandas Series, or vice versa

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages