How can I use .isin for pandas where it will use values from each of the rows in the dataframe, and not static values.
For example lets say we have dataframe like:
import pandas as pd
import datetime
l = []
for i in range(100000):
d = {'a':i,'b':{1,2,3},'c':0}
l.append(d)
df = pd.DataFrame(l)
If I use .isin, it can only take 1 list of values (in this example {1,2,3}) and will be compared to each of the values in the column you want to compare (ie df['a'])
test = df['a'].isin({1,2,3})
If I want to compare each value of the column 'b' if values in 'a' is in df['b'] I can do the following below:
def check(a, b):
return a in b
test = list(map(check, df['a'], df['b']))
Of course in this example all values in df['b'] is the same, but can pretend it is not.
Unfortunately this is about 5x slower than just using the .isin. My question is, is there a way to use .isin but for each of the values in df['b]? Or dont have to necessarily use .isin, but what would be a more efficient way to do it?