Count unique values per groups with Pandas [duplicate]
You need nunique: If you need to strip ‘ characters: Or as Jon Clements commented: You can retain the column name like this: The difference is that nunique() returns a Series and agg() returns a DataFrame.