Consider the following dataframe:
A B E
0 bar one 1
1 bar three 1
2 flux six 1
3 flux three 2
4 foo five 2
5 foo one
I encountered the same problem. Upgrading pandas to the latest version solved the problem for me.
df.groupby('A').nunique()
The above code did not work for me in Pandas version 0.19.2. I upgraded it to Pandas version 0.21.1 and it worked.
You can check the version using the following code:
print('Pandas version ' + pd.__version__)