A package that adds the notin method to pandas.Series and pandas.DataFrame objects
Project description
not-in-pandas
Adds notin method to pandas.Series and pandas.DataFrame objects. Returns exactly the same as negating isin
.
Installation
Use pip to install not-in-pandas.
pip install not-in-pandas
Usage
import pandas as pd
import not_in_pandas
# on Series
>>> s = pd.Series(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'], name='animal')
>>> s.notin(['cow', 'lama'])
0 False
1 False
2 False
3 True
4 False
5 True
Name: animal, dtype: bool
# on DataFrame
>>> df = pd.DataFrame(
... {
... "animal_a": ["lama", "cow", "lama", "beetle", "lama"],
... "animal_b": ["cow", "beetle", "cow", "hippo", "lama"]
... }
... )
>>> df.notin(['cow', 'lama'])
animal_a animal_b
0 False False
1 False True
2 False False
3 True True
4 False False
5 True True
Why this isn't already on Pandas?
Pandas core developers thought this method would be redundant, because you achieve the same results by negating a isin method ~Series.isin(['lama', 'cow'])
. And main files on the Pandas package are already huge and difficult to navigate, so I understand their reluctancy on adding more unnecessary stuff.
I personally think this method:
- Improves readability a lot, specially with nested conditions
- Keeps consistency with other
not
methods likeSeries.notna
orSeries.notnull
- Is consistent with raw Python logic
a not in b
- Makes starting programmers less annoyed because they don't find a method they think should exist (and avoids a Google search), specially if they know that
.notna
already exists - I use
.isin
a lot
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
File details
Details for the file not-in-pandas-0.1.1.tar.gz
.
File metadata
- Download URL: not-in-pandas-0.1.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f5b866b5aa3e1aa7919303fc524f2cb2febe96d87ec0b603ef5920845e1ca8a |
|
MD5 | 8129653763d9af93ece8c0b587f5b505 |
|
BLAKE2b-256 | a490367ce981b8be91426f19b8b099d2b4b96e8d0646627a877282f642a17af3 |
File details
Details for the file not_in_pandas-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: not_in_pandas-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b34f0b0f7b7d516b2d1477a989223322da33da2e585a40055d4807bdcbbae85 |
|
MD5 | 7320161a22cb996a87ffa1f237cbf220 |
|
BLAKE2b-256 | 32c8fb5ed24e164c67ea38af24c52ca23ce557a603f50e6817528412db6db725 |