Skip to main content

Add a select accessor to pandas

Project description

pandas-selectable

test status

What Is It?

pandas-selectable adds a select accessor to pandas DataFrames and Series. It's like query but with the niceties of tab-completion.

Quickstart

In [1]: import numpy as np

In [2]: import pandas as pd

In [3]: import pandas_selectable  # magic

In [4]: dta = pd.DataFrame.from_dict({
   ...:     'A': ['A', 'B', 'C'] * 5,
   ...:     'B': np.arange(1, 16),
   ...:     'C': pd.date_range('2020-01-01', periods=15)
   ...: })

In [5]: dta.head()
Out[5]:
   A  B          C
0  A  1 2020-01-01
1  B  2 2020-01-02
2  C  3 2020-01-03
3  A  4 2020-01-04
4  B  5 2020-01-05

In [6]: dta.select.A == 'B'
Out[6]:
    A   B          C
1   B   2 2020-01-02
4   B   5 2020-01-05
7   B   8 2020-01-08
10  B  11 2020-01-11
13  B  14 2020-01-14

In [7]: dta.select.C >= '2020-01-03'
Out[7]:
    A   B          C
2   C   3 2020-01-03
3   A   4 2020-01-04
4   B   5 2020-01-05
5   C   6 2020-01-06
6   A   7 2020-01-07
7   B   8 2020-01-08
8   C   9 2020-01-09
9   A  10 2020-01-10
10  B  11 2020-01-11
11  C  12 2020-01-12
12  A  13 2020-01-13
13  B  14 2020-01-14
14  C  15 2020-01-15

In [8]: dta.select.A.str.contains('A')
Out[8]:
    A   B          C
0   A   1 2020-01-01
3   A   4 2020-01-04
6   A   7 2020-01-07
9   A  10 2020-01-10
12  A  13 2020-01-13

In [9]: dta.select.C.dt.is_month_start
Out[9]:
   A  B          C
0  A  1 2020-01-01

It also works for Series.

In [10]: dta.A.select == 'A'
Out[10]:
0     A
3     A
6     A
9     A
12    A
Name: A, dtype: object

Though the string and datetime accessor APIs are slightly inconsistent. They're available via the select accessor now.

In [11]: dta.A.select.str.contains('B')
Out[11]:
1     B
4     B
7     B
10    B
13    B
Name: A, dtype: object

Requirements

pandas >= 1.1

Installation

pip install pandas-selectable

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

pandas_selectable-1.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

pandas_selectable-1.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file pandas_selectable-1.1.0.tar.gz.

File metadata

  • Download URL: pandas_selectable-1.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pandas_selectable-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c8ed77272f1a0dacf82ebb8ace72afcfbace719240834ac155442307f9bd435e
MD5 c0eb8f8b6b354c011e74ac159f908392
BLAKE2b-256 65842a53377396f59709c0dfe91319df9a7d372d335e3d7212c28ea4ff3a1cfb

See more details on using hashes here.

File details

Details for the file pandas_selectable-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pandas_selectable-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pandas_selectable-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4cfd66475bc7f65357f515feccae9323b86cd4c1bc65567e48310a5c14d0aca
MD5 7a1b5552a59385e3ae86604be769bb00
BLAKE2b-256 f98d61c09278d90821b49bc0fffd499ab0597a07e016cac2c1129993d8d7e69b

See more details on using hashes here.

Supported by

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