get_intersection
- trashpanda.get_intersection(source: pandas.core.frame.DataFrame, targeted_indexes: Union[List, pandas.core.indexes.base.Index]) pandas.core.frame.DataFrame
- trashpanda.get_intersection(source: pandas.core.series.Series, targeted_indexes: Union[List, pandas.core.indexes.base.Index]) pandas.core.series.Series
Intersects Series or DataFrame by requested indexes. A subsection from the source is made for the targeted_indexes, which must not necessaraly be whithin the source.
- Parameters
source (Union[DataFrame, Series]) – Values from which an intersection will be retrieved.
targeted_indexes (Index) – The indexes which the returned Series should contain.
- Returns
Union[DataFrame, Series]
Examples
Usage with pandas.Series
>>> from pandas import Series >>> sample_series = Series(list(range(3)), index=list(iter("abc")), name="foo") >>> get_intersection(sample_series, ["b", "c", "d"]) b 1 c 2 Name: foo, dtype: int64 >>> get_intersection(sample_series, ["x", "y", "z"]) Series([], Name: foo, dtype: int64)
Usage with pandas.DataFrame
>>> from pandas import DataFrame >>> sample_series = DataFrame( ... list(range(3)), index=list(iter("abc")), columns=["foo"] ... ) >>> get_intersection(sample_series, ["b", "c", "d"]) foo b 1 c 2 >>> get_intersection(sample_series, ["x", "y", "z"]) Empty DataFrame Columns: [foo] Index: []