Input DataFrame :
data = { "id" : ['[1,2]','[2,4]','[4,3]'],
"name" : ['a','b','c'] }
df = pd.DataFrame(data)
filterstr = [1,2]
Expected Output:
id name
[1,2] a
[2,4] b
Tried Code :
df1 = df[df.id.map(lambda x: np.isin(np.array(x), [[ str([i]) for i in filter]]).all())]
This works for single value in id column but not for two values like '[1,2]' Not sure where i am going wrong.
idcolumn is a list or a string representation of a list? In the last case, is it safe to convert it as a list? Yourfilterstris a list?