Skip to main content

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 ChatGPT which really helps to speed up responses and keep the conversation on track.

This is also a refactor of old code I wrote 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transude-2.0.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

transude-2.0.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file transude-2.0.0.tar.gz.

File metadata

  • Download URL: transude-2.0.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for transude-2.0.0.tar.gz
Algorithm Hash digest
SHA256 db59c29fffc3717bb537b320724b31d711393f4b729385b421a047d8afb5ceab
MD5 7986fcb65162fd6e5edc4d9366d31ea2
BLAKE2b-256 b27e55795a9bec8d1819e1299e5f81c355ad7b66dc471284fa096096145fb4ae

See more details on using hashes here.

File details

Details for the file transude-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: transude-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for transude-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fef68f55800868f81999441202551a7b782747f2b63c0814be2d84cbd49d3c69
MD5 9d7a26b1b483be664a9273c1064b02af
BLAKE2b-256 c3fdcd2f834e0ee426a152c8ad736390885485b920e8dfd5dcefc788fa7c5555

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page