return IT.chain.from_iterable(IT.combinations(s, r) for r in rvals)
df = pd.DataFrame(np.random.randint(2, size=(10, 4)), columns=list('ABCD'))
print(df)
for cols in powerset(df.columns):
    if not cols:
        continue
for vals in IT.product([0, 1], repeat=len(cols)):
    mask = np.logical_and.reduce([(df[c] == v) for c, v in zip(cols, vals)])
cond = ' & '.join(['{}={}'.format(c, v) for c, v in zip(cols, vals)])
n = len(df[mask])
print('n({}) = {}'.format(cond, n))
How to use python pandas to get intersection of sets from a csv file