oakca
oakca

Reputation: 1568

Check any element of an array inside a list

Assume I got an array, created by a pandas dataframe with array = df.index.values and looks like following:

array
array(['A', 'B', 'C', 'D',
       'E', 'F', 'G', 'H'], dtype=object)

and I got a python list looks like following:

list = ['AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'A']

Looking for a function, which does following:

If any element of array is also in list, give me True. If not give me False.

PS: I am not looking for finding the element. Just want to know if such element exist.

Upvotes: 0

Views: 284

Answers (1)

jezrael
jezrael

Reputation: 863226

Pandas solution with Index.isin and Index.any:

df.index.isin(List).any()

Upvotes: 2

Related Questions