How to obtain unique count of categorical variable based on another categorical variable?
Try nunique(). That should do it. Here is a toy example:

import pandas as pd

df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar',
                          'foo', 'bar', 'foo', 'foo'],
                   'B' : ['one', 'one', 'two', 'three',
                          'two', 'two', 'one', 'two']})

print(df)


gives

     A      B
0  foo    one
1  bar    one
2  foo    two
3  bar  three
4  foo    two
5  bar    two
6  foo    one
7  foo    two


and 

print(df.groupby('A')['B'].nunique())


then gives

A
bar    3
foo    2
Name: B, dtype: int64


For more details check this question on SO.