Skip to main content

Pandas utility for handling very wide DataFrames

Project description

querycolumn

Simple extension to Pandas that makes it easier to select columns in (very) wide DataFrames. If you name your columns in a hierarchical fashion with a separator (e.g, as you might get from pd.normalize_json(), it lets you select a column or group of columns easily and with tab completion.

Here's a quick demo of what this looks like.

    >>> import pandas as pd
    >>> from querycolumn import patch_dataframe_with_query_columns
    >>> patch_dataframe_with_query_columns()
    >>> df = pd.DataFrame([{'person.size.height': 3, 'person.size.weight': 4}])
    >>> df.qc.person
    <QueryColumns @ person: size>
    >>> df.qc.person.size
    <QueryColumns @ person.size: height, weight>
    >>> df.qc.person.size.weight
    0    4
    Name: person.size.weight, dtype: int64
    >>> df[df.qc.person.size]
    >>> 

QueryColumns does its magic by patching a Descriptor into the DataFrame class. When you retrieve the attribute qc from a frame, `QueryColumns.get()' is invoked; this is when QueryColumns introspects its parent dataframe and returns a magical object with tab completion for segmented column names.

Note I wrote QueryColumns after working with Pandas for about a week. I don't know if it encourages elegant use of the library, but I find it useful for my usecase. I'm practically certain that it doesn't extend Pandas as one should (there are explicit APIs for that), but I couldn't think of a way to do it without the Descritor protocol.

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

querycolumns-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

querycolumns-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file querycolumns-0.1.0.tar.gz.

File metadata

  • Download URL: querycolumns-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for querycolumns-0.1.0.tar.gz
Algorithm Hash digest
SHA256 168d15ea1184e960d9325dd01c309bcf391adc285f147a01fca15582c842e7bb
MD5 ff8e7a24ae66b0c072f5d0c0351dbbdc
BLAKE2b-256 77b45db4a57922c7ffd154b4cfbf0a7b0eccca0f4721e30fe451f5901745b772

See more details on using hashes here.

File details

Details for the file querycolumns-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: querycolumns-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for querycolumns-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 139960401a26e94229a7b57a89298aebd525a8551e208db7a123639ada831d04
MD5 82c57f57426315b9ca35f313b0ecb64e
BLAKE2b-256 f06b83312cc63fcb95c63f937402b7960e284e0cdadb907985582dc30fa1394b

See more details on using hashes here.

Supported by

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