pandas-select

Supercharged DataFrame indexing


Keywords
pandas, scikit-learn, pandera, python
License
BSD-3-Clause
Install
pip install pandas-select==0.2.0

Documentation

pandas-select: Supercharged DataFrame indexing

Github Actions status Coverage Documentation status Latest PyPI version Python versions supported License Code style: black

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 the excellent R library tidyselect.

Installation

pandas-select is a Python-only package hosted on PyPI. It can be installed via pip:

pip install pandas-select

Design goals

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

# pandas-select
df[StartsWith("Type") | "Legendary"]
# vanilla
df.loc[:, df.columns.str.startswith("Type") | (df.columns == "Legendary")]
# pandas-select
df_mi.loc[Contains("Jeff", axis="index", level="Name")]

# vanilla
df_mi.loc[df_mi.index.get_level_values("Name").str.contains("Jeff")]
  • Play well with machine learning applications.

    • Respect the columns order.

    • Allow deferred selection when the DataFrame's columns are not known in advance, for example in automated machine learning applications.

    • Offer 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+.