daproli is a small data processing library that attempts to make data transformation more declarative.
Project description
daproli
A small data processing library that attempts to make data transformation more declarative.
Installation
You can install daproli with PyPi:
python -m pip install daproli
Examples
Let's first import daproli.
>>> import daproli as dp
The library provides basic data transformation methods.
>>> names = ['John', 'Susan', 'Mike']
>>> numbers = range(10)
>>> even_numbers = range(0, 10, 2)
>>> odd_numbers = range(1, 10, 2)
>>> dp.map(str.lower, names)
['john', 'susan', 'mike']
>>> dp.filter(lambda n : len(n) % 2 == 0, names)
['John', 'Mike']
>>> dp.split(lambda x : x % 2 == 0, numbers)
[[1, 3, 5, 7, 9], [0, 2, 4, 6, 8]]
>>> dp.expand(lambda x : (x, x**2), numbers)
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]]
>>> dp.combine(lambda x, y : (x,y), even_numbers, odd_numbers)
[(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]
>>> dp.join(lambda x, y : y-x == 3, even_numbers, odd_numbers)
[(0, 3), (2, 5), (4, 7), (6, 9)]
daproli implements basic data manipulation functions.
>>> dp.windowed(numbers, 2, step=2)
[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]
>>> dp.flatten([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Additionally, it provides a data transformation pipeline framework.
>>> dp.Pipeline(
dp.Splitter(lambda x: x % 2 == 1),
dp.Union(
dp.Mapper(lambda x: x * 2),
dp.Mapper(lambda x: x * 3),
),
dp.Joiner(lambda x1, x2: (x1 + x2) % 5 == 0),
dp.Filter(lambda x1, x2: x1 + x2 < 30),
dp.Manipulator(sorted),
).transform(numbers)
[(0, 15), (4, 21), (12, 3), (16, 9)]
>>> dp.Pipeline(
dp.Filter(lambda x : x > 1),
dp.Filter(lambda x : all(x % idx != 0 for idx in range(2, x))),
).transform(numbers)
[2, 3, 5, 7]
You can find more examples here.
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
daproli-0.19.tar.gz
(6.8 kB
view hashes)
Built Distribution
daproli-0.19-py3-none-any.whl
(9.4 kB
view hashes)