Skip to main content

Supercharged DataFrame indexing

Project description

Github Actions status Coverage Documentation status Latest PyPI version Python versions supported License Code style: black https://img.shields.io/badge/style-wemake-000000.svg

pandas-select is a collection of DataFrame selectors that facilitates indexing and selecting data, fully compatible with pandas vanilla indexing.

The selector functions can choose variables based on their name, data type, arbitrary conditions, or any combination of these.

pandas-select is inspired by two R libraries: tidyselect and recipe.

Installation

pandas-select is a Python-only package hosted on PyPI. The recommended installation method is pip-installing into a virtualenv:

$ pip install pandas-select

Design goals

df[AllNumeric()] # pandas-select
df.select_dtypes(exclude="number").columns # vanilla

df[StartsWith("Type") | "Legendary"] # pandas-select

 # vanilla
df[df.select_dtypes(exclude="number").columns]
cond = lambda col: col.startswith("Type") or col == "Legendary"
cols = [col for col in df.columns if cond(col)]
df[cols]
# pandas-select
selector = Contains("Jeff", axis="index", level="Name")
df_mi.loc[selector]

# vanilla
selector = df_mi.index.get_level_values("Name").str.contains("Jeff")
df_mi.loc[selector]
  • Allow deferred selection when the DataFrame’s columns are not known in advance, for example in automated machine learning applications. pandas_select offers integration with sklearn.
from pandas_select import AnyOf, AllBool, AllNominal, AllNumeric, ColumnSelector
from sklearn.compose import make_column_transformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler

ct = make_column_transformer(
    (StandardScaler(), ColumnSelector(AllNumeric() & ~AnyOf("Generation"))),
    (OneHotEncoder(), ColumnSelector(AllNominal() | AllBool() | "Generation")),
)
ct.fit_transform(df)

Project Information

pandas-select is released under the BS3 license, its documentation lives at Read the Docs, the code on GitHub, and the latest release on PyPI. It is tested on Python 3.6+.

Project details


Download files

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

Files for pandas-select, version 0.1.7
Filename, size File type Python version Upload date Hashes
Filename, size pandas_select-0.1.7-py3-none-any.whl (15.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pandas-select-0.1.7.tar.gz (15.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page