dtoolkit.accessor.series.filter_in#

dtoolkit.accessor.series.filter_in(s: Series, condition: Iterable, /, complement: bool = False) Series[source]#

Filter Series contents.

Similar to isin(), but the return is not bool.

Parameters
conditionlist-like

The filtered result is based on this specific condition.

complementbool, default is False

If True, do operation reversely.

Returns
Series

Examples

>>> import dtoolkit
>>> import pandas as pd
>>> s = pd.Series(
...     ['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'],
...     name='animal',
... )
>>> s
0      lama
1       cow
2      lama
3    beetle
4      lama
5     hippo
Name: animal, dtype: object
>>> s.filter_in(['cow', 'lama'])
0      lama
1       cow
2      lama
4      lama
Name: animal, dtype: object
>>> s.filter_in(['cow', 'lama'], complement=True)
3    beetle
5     hippo
Name: animal, dtype: object