# Search for multiple values in multiple columns of a Pandas DataFrame
```python
pip install a-pandas-ex-multiloc
```
```python
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))]
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/a_pandas_ex_multiloc",
"name": "a-pandas-ex-multiloc",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "pandas,DataFrame,loc,iloc",
"author": "Johannes Fischer",
"author_email": "<aulasparticularesdealemaosp@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/f9/6a/196f0698233869d377b5c23f6735e808f96541c5ea090a786b4c23367c1b/a_pandas_ex_multiloc-0.10.tar.gz",
"platform": null,
"description": "\n# Search for multiple values in multiple columns of a Pandas DataFrame\n\n\n\n```python\n\npip install a-pandas-ex-multiloc\n\n```\n\n\n\n```python\n\n\n\nfrom random import randrange\n\nfrom a_pandas_ex_multiloc import pd_add_multiloc\n\nimport pandas as pd\n\n\n\npd_add_multiloc()\n\ndf = pd.DataFrame(\n\n [(randrange(0, 256), randrange(0, 256), randrange(0, 256)) for k in range(100000)],\n\n columns=[\"r\", \"g\", \"b\"],\n\n)\n\n\n\n\n\n\n\ndf.d_multiloc(\n\n column_and_values=[\n\n (\n\n \"==\",\n\n (\"r\", \"g\", \"b\"),\n\n ((166, 16, 169), (1, 0, 0), (18, 38, 64), (11, 14, 45), (11, 14, pd.NA)),\n\n )\n\n ],\n\n)\n\n\n\n# the same as:\n\n# 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))]\n\n\n\n# NaN has to be passed as: pd.NA\n\n\n\ndf.d_multiloc(\n\n column_and_values=[(\"==\", (\"r\", \"g\", \"b\"), ((11, 14, 45), (11, 14, pd.NA)))],\n\n)\n\n# the same as: df.loc[((df['r'] == 11)&(df['g'] == 14)&(df['b'] == 45))|((df['r'] == 11)&(df['g'] == 14)&(df['b'] == pd.NA))]\n\n\n\n# not all values need to be inside each tuple\n\ndf.d_multiloc(\n\n column_and_values=[(\"==\", (\"r\", \"g\", \"b\"), ((11, 14, 45), (11,), (16, 100)))],\n\n)\n\n# the same as: df.loc[((df['r'] == 11)&(df['g'] == 14)&(df['b'] == 45))|((df['r'] == 11))|((df['r'] == 16)&(df['g'] == 100))]\n\n\n\n\n\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Search for multiple values in multiple columns of a Pandas DataFrame",
"version": "0.10",
"split_keywords": [
"pandas",
"dataframe",
"loc",
"iloc"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "487a501cbb4fca8d647c474044b721b7",
"sha256": "db878cc2e9575d87d6257b3374b762b7ffe2975a7a7186c247dfd0c8b1687229"
},
"downloads": -1,
"filename": "a_pandas_ex_multiloc-0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "487a501cbb4fca8d647c474044b721b7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5222,
"upload_time": "2022-12-19T09:07:12",
"upload_time_iso_8601": "2022-12-19T09:07:12.364561Z",
"url": "https://files.pythonhosted.org/packages/a3/b4/71fa1f91dd0e17f058b1ad49066b81e87262c8b427e2560c4923c8468eef/a_pandas_ex_multiloc-0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "4415715b2ca4330e1f8095ad6c942b4e",
"sha256": "0bb69eb595d92b48080b244082d42407cf39b25ee63e7e009aaf56cc955bd9a3"
},
"downloads": -1,
"filename": "a_pandas_ex_multiloc-0.10.tar.gz",
"has_sig": false,
"md5_digest": "4415715b2ca4330e1f8095ad6c942b4e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3702,
"upload_time": "2022-12-19T09:07:15",
"upload_time_iso_8601": "2022-12-19T09:07:15.289563Z",
"url": "https://files.pythonhosted.org/packages/f9/6a/196f0698233869d377b5c23f6735e808f96541c5ea090a786b4c23367c1b/a_pandas_ex_multiloc-0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-19 09:07:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "hansalemaos",
"github_project": "a_pandas_ex_multiloc",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "pandas",
"specs": []
}
],
"lcname": "a-pandas-ex-multiloc"
}