One way to test if a value occurs in a column in a Pandas data frame is to count the occurrences of each value, so for example if we want to check for the occurrence of 'dog' in the column 'pet' we could do this
at_least_one_dog = df['pet'].value_counts()['dog'] > 0
or we could check that it is in the list of all the values in the column like this
at_least_one_dog = 'dog' in df['pet'].unique()
But both of these methods process the entire column before producing an answer, which can be time consuming for a very large data frame. Is there a way to test for the occurrence of a value in a column that returns True
immediately the first occurrence is encountered without necessarily going through the whole column?