pandas groupby size column name

Solutions on MaxInterview for pandas groupby size column name by the best coders in the world

showing results for - "pandas groupby size column name"
Emilia
04 Mar 2017
1import pandas as pd
2
3df = pd.DataFrame({'A': ['x', 'x', 'x','y','y']
4                , 'B': ['a', 'c', 'c','b','b']})
5print (df)
6   A  B
70  x  a
81  x  c
92  x  c
103  y  b
114  y  b
12
13df = df.groupby(['A', 'B']).size().reset_index(name='Size')
14print (df)
15   A  B  Size
160  x  a     1
171  x  c     2
182  y  b     2
19