Delosari
Delosari

Reputation: 693

Check if a pandas series contains a set of variables:

In a python dictionary it is very clean to make the following check:

import pandas as pd

myDict      = {'a':1, 'b':2, 'c':3}
mySeries    = pd.Series(data = [1,2,3], index = ['a', 'b', 'c']) 

if myDict.viewkeys() >= {'a', 'b'}:
    print 'a and b are in dictionary'

However, I cannot find a easy way to do the same with a pandas series... Which is the pythonic way?

Upvotes: 0

Views: 506

Answers (1)

DeepSpace
DeepSpace

Reputation: 81594

A short answer, but you can simply convert the series to set and then use the same methodology you used with the dictionary:

df = pd.Series(data = [1, 2, 3], index = ['a', 'b', 'c'])
print(set(df) >= {1, 2})
# True

Upvotes: 2

Related Questions