ex = pd.DataFrame([[1, 2, 3], [6, 7, 8], [1, 7, 9]], columns=['A', 'B', 'C']
    ).set_index(['A', 'B'])
A_val, nunique_B = zip(*[(k, len(Counter(v.index.labels[v.index.names.index
    ('B')]))) for k, v in ex.groupby(level='A')])
pd.Series(nunique_B, index=pd.Int64Index(A_val, name='A'))
Counting unique index values in Pandas groupby