I have a DataFrame and a List. Every Item of the DataFrame that doesn't match with the Item in the List should be set to None. I wrote a list comprehension which should check if that the item is not in the list is True and in this case should set the item of the DataFrame to None. Can someone Explain me why I get a ValueError. I tried the methods recommended from the ValueError but they didn't work.
My Code:
abc = ['A', 'B', 'C']
l = ['A', 'B', 'None', '5-20', 'C', '200-500', 'D', '1000', 'A']
l = pd.DataFrame(l)
[None for i in l if ~l[i].isin(abc) == True]
print(l)
Output:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
Expected Result:
0
0 A
1 B
2 None
3 None
4 C
5 None
6 None
7 None
8 A