Equivalent Of "in" Keyword Or Subquery In Pandas
I have a Series object (let's call this MySeries) which contains a list of integers. I also have a separate dataframe (say MyDataFrame), which includes a column/field called MyF
Solution 1:
you can use isin() function:
>>>df = pd.DataFrame({'A':[1,2,3,4,5], 'B':list('ABCDE')})>>>f = pd.Series([1,2])>>>df[df['A'].isin(f)]
A B
0 1 A
1 2 B
so, first you get fiter Series:
>>> df['A'].isin(f)
0True1True2False3False4False
And then use it to filter your DataFrame
Post a Comment for "Equivalent Of "in" Keyword Or Subquery In Pandas"