i have a Series Object in pandas with 2 columns, one for the indices and one with lists, I need to find if a value occurs in only one of these lists and return it with the most optimal way.
As an example let’s say we have this
i need to return 77 because it occurs in only one of these lists.
Advertisement
Answer
You can use explode
then value_counts
:
df['list_col'].explode().value_counts().loc[lambda x: x==1]