print(d.groupby(['ip', 'useragent']).size().reset_index().rename(columns={0:''}))
gives:
ip useragent
0 192.168.0.1 a 2
1 192.168.0.1 b 1
2 192.168.0.2 b 1
Another nice option might be pandas.crosstab:
print(pd.crosstab(d.ip, d.useragent) )
print('\nsome cosmetics:')
print(pd.crosstab(d.ip, d.useragent).reset_index().rename_axis('',axis='columns') )
gives:
useragent a b
ip
192.168.0.1 2 1
192.168.0.2 0 1
some cosmetics:
ip a b
0 192.168.0.1 2 1
1 192.168.0.2 0 1