phoenix
phoenix

Reputation: 338

check if all the values of list is in dataframe column

I have a list which has string values.

Example: listofwords = ['A, 'B', 'C'] . I have a dataframe with a column. I want my code to return True if all the values in the list is in that column.

How can I do this?

Upvotes: 0

Views: 219

Answers (1)

Serial Lazer
Serial Lazer

Reputation: 1669

Create sets for both and take set-compliment, if its empty that means all items of listofwords are in the Dataframe_column:

len(set(listofwords) - set(df['Dataframe_Column'])) == 0 

Upvotes: 1

Related Questions