<human>:  Counting unique index values in Pandas groupby
<bot>: Here is some code to count unique index values in column 'A' in pandas dataframe `ex`

ex.groupby(level='A').agg(lambda x: x.index.get_level_values(1).nunique())

#Warning: this code generation is experimental. Please inspect the code for any bugs before executing.