Simple tool set for filtering DataFrames by building queries from one or more filters.
Project description
Transude
Simple tool set for filtering DataFrames (Pandas or Polars*) by building queries from one or more filters. This is useful for connecting filtering controls on DataFrames using touch screen controls.
This project was developed with some consulting from ChatGPT. There were a few concepts I didn't understand until I had someone I could point more specific questions towards and see working examples. Most of the scaffolding was written before consulting as it really tends to speed up responses and keep the conversation on track. This is also a refactor of old code I used in a recent project.
Installation:
pip install transude
Usage:
import pandas as pd
import transude as txd
# Create a DataFrame using Pandas
pd_df = pd.DataFrame(...)
# Get a filtered version of the DataFrame using Transude
filtered_pd_df = txd.filter_df(data_frame=pd_df, columns='col1', values=['val1', 'val2'], operator='==', joiner='or')
If you need to manage the DataFrameFilters directly, you can use a DataFrameFilterManager like so:
pd_df_filter_manager = DataFrameFilterManager()
# Example of adding a single DataFrameFilter and clearing the filters. Filters can be removed one by one as well.
pd_df_filter_manager.add_filter(DataFrameFilter(columns='col1', values='val1', operator='==', joiner='or'))
pd_df_filter_manager.clear_filters()
# The following utilizes the DataFrameFilterFactory to create multiple filters and then adds them all to the builder.
pd_filter_factory = DataFrameFilterFactory(columns='col1', values=['val1', 'val2'], operator='==', joiner='or')
pd_filters = pd_filter_factory.create_filters()
pd_df_filter_manager.add_filters(pd_filters)
query_string = pd_df_filter_manager.build_query()
# In order to apply the filters, call query using the query_string
pd_df.query(query_string)
--*Polars compatability coming soon.
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 transude-1.1.7.tar.gz
.
File metadata
- Download URL: transude-1.1.7.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99db778b2159bf07b87a475a92749a4ee713c86b18f16684f97c9091574a0de3 |
|
MD5 | 4aaafc6fa85a04deffedd876c996d8df |
|
BLAKE2b-256 | 6e56a8d6a2ebba77184a4b8b228480066f7a92a4453da78dfcfd56fb65ecfff1 |
File details
Details for the file transude-1.1.7-py3-none-any.whl
.
File metadata
- Download URL: transude-1.1.7-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 237ecf918c8eb5a22fdb001635ccd3ea7b37968c712c65cdf3a17b81330b548a |
|
MD5 | ac7eecc025f34bdc120092989f9ec16d |
|
BLAKE2b-256 | 3b05c1408ec9391fb03a50ae1e86e095e947fd14334f183c2db160fedfcef59c |