I have the following dataframe
import pandas as pd
import numpy as np
df = pd.DataFrame()
df['Name'] = ['AK', 'Ram', 'Ram', 'Singh', 'Murugan', 'Kishore', 'AK']
df['Email'] = ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']
df['Cat'] = ['ab1', 'ab2', 'ab1', 'ab2', 'ab1', 'ab2', 'ab1']
df['Id'] = ['abc1', 'abc2', 'abc3', 'abc4', 'abc5', 'abc6', 'abc7']
For the following code
dfs=df.groupby(['Email', 'Cat'])['Email'].count().reset_index(name='Number')
It gives:
Email Cat Number
0 [email protected] ab2 1
1 [email protected] ab1 2
2 [email protected] ab1 1
3 [email protected] ab2 1
4 [email protected] ab2 1
5 [email protected] ab1 1
How to group by on dfs to get the following output?
Cat Number Count
ab1 1 3
ab1 2 1
ab2 1 3