Reputation: 3125
For example:
import pandas as pd
data = ['A2', 'A5', 'XS', '2X', '8W']
codes = {'codes':[data]}
df = pd.DataFrame(codes)
codes
0 [A2, A5, XS, 2X, 8W]
Now I want to test to see if certain values are in my list from another list.
df['wo'] = df.codes.isin(["8C", "8D", "8E", "8W", "A2"])
I keep getting TypeError: unhashable type: 'list'
How do I fix this?
Upvotes: 1
Views: 1138
Reputation: 294258
pandas
and set
You can use sets. When subtracting sets you get set differences. When comparing sets, you get proper subsets. When a set differenced with another set is a proper subset of that same set... then there was an intersection.
s = df.codes.apply(set)
s - set(["8C", "8D", "8E", "8W", "A2"]) < s
0 True
Name: codes, dtype: bool
Upvotes: 3