Search for multiple values in multiple columns of a Pandas DataFrame
Project description
Search for multiple values in multiple columns of a Pandas DataFrame
pip install a-pandas-ex-multiloc
from random import randrange
from a_pandas_ex_multiloc import pd_add_multiloc
import pandas as pd
pd_add_multiloc()
df = pd.DataFrame(
[(randrange(0, 256), randrange(0, 256), randrange(0, 256)) for k in range(100000)],
columns=["r", "g", "b"],
)
df.d_multiloc(
column_and_values=[
(
"==",
("r", "g", "b"),
((166, 16, 169), (1, 0, 0), (18, 38, 64), (11, 14, 45), (11, 14, pd.NA)),
)
],
)
# the same as:
# df.loc[((df['r'] == 166)&(df['g'] == 16)&(df['b'] == 169))|((df['r'] == 1)&(df['g'] == 0)&(df['b'] == 0))|((df['r'] == 18)&(df['g'] == 38)&(df['b'] == 64))|((df['r'] == 11)&(df['g'] == 14)&(df['b'] == 45))|((df['r'] == 11)&(df['g'] == 14)&(df['b'] == pd.NA))]
# NaN has to be passed as: pd.NA
df.d_multiloc(
column_and_values=[("==", ("r", "g", "b"), ((11, 14, 45), (11, 14, pd.NA)))],
)
# the same as: df.loc[((df['r'] == 11)&(df['g'] == 14)&(df['b'] == 45))|((df['r'] == 11)&(df['g'] == 14)&(df['b'] == pd.NA))]
# not all values need to be inside each tuple
df.d_multiloc(
column_and_values=[("==", ("r", "g", "b"), ((11, 14, 45), (11,), (16, 100)))],
)
# the same as: df.loc[((df['r'] == 11)&(df['g'] == 14)&(df['b'] == 45))|((df['r'] == 11))|((df['r'] == 16)&(df['g'] == 100))]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file a_pandas_ex_multiloc-0.10.tar.gz.
File metadata
- Download URL: a_pandas_ex_multiloc-0.10.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bb69eb595d92b48080b244082d42407cf39b25ee63e7e009aaf56cc955bd9a3
|
|
| MD5 |
4415715b2ca4330e1f8095ad6c942b4e
|
|
| BLAKE2b-256 |
f96a196f0698233869d377b5c23f6735e808f96541c5ea090a786b4c23367c1b
|
File details
Details for the file a_pandas_ex_multiloc-0.10-py3-none-any.whl.
File metadata
- Download URL: a_pandas_ex_multiloc-0.10-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db878cc2e9575d87d6257b3374b762b7ffe2975a7a7186c247dfd0c8b1687229
|
|
| MD5 |
487a501cbb4fca8d647c474044b721b7
|
|
| BLAKE2b-256 |
a3b471fa1f91dd0e17f058b1ad49066b81e87262c8b427e2560c4923c8468eef
|