how to find number of categories in python
from collections import Counter df = pd.DataFrame({'a':['apple','apple','banana','peach', 'banana', 'apple']}) print Counter(df['a']) >> Counter({'apple': 3, 'banana': 2, 'peach': 1})
Here is what the above code is Doing:
1. Create a dataframe with a column ‘a’
2. Create a Counter object from the column ‘a’
3. Print the Counter object