petl_addons
This is a library that adds
Installation
pip install petl_addons
Usage
import petl_addons
apply
This patches the petl Table class with an apply method calls the specified function
with the table. This allows pipeline fragments to be defined and applied in a clear format.
def filter_values(table):
return table.selecteq('value', 10).selectnotnone('name')
table.apply(filter_values)
args and kwargs are passed through to the function:
def op(table, field, inflation=10):
return table.convert(field, lambda f: f+inflation)
table.apply(op, 'value', inflation=20) // Will inflate the value field by 20
Multiple separate fragments can be chained together, greatly enhancing code readability and reusability.
table.apply(filter_values).apply(summarise_data).apply(write_csv)
The module also overloads the | character to allow the following usage, equivalent to the
example above:
table | filter_values | summarise_data | write_csv
NB this won't work with parameter functions.
If you wish to load this on its own without any other modules, use the statement below.
import petl_addons.apply
Metadata
Release files for petl-addons 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| petl_addons-0.0.1.tar.gz | 16.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| petl_addons-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.9 kB
Release files / petl_addons-0.0.1.tar.gz
| Download URL | petl_addons-0.0.1.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4a79cfb061a78f2378b058a52e7d7751e4a4af1de970b71d4c3416b0d9c18f2
|
|
BLAKE2b-256 checksum How to use checksums |
eeaada7b08af6a8d602d453d405b797831127779fdef678c9511c60b6996267d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.4
|
Release files / petl_addons-0.0.1-py3-none-any.whl
| Download URL | petl_addons-0.0.1-py3-none-any.whl |
|---|---|
| Size | 2.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a34b46894f838217cd7d8f58f124e357fcb4cb00d28c9f2bc3e460f9cd39cee7
|
|
BLAKE2b-256 checksum How to use checksums |
77ab3918fcec2db78a7c2f799f28c2a08f2efa30cd484e3ca068d9d0b571d4f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.4
|