Is there an efficient way to group by and create a count col in a data frame containing a single column.
I tried but involves creating an extra col in original dataframe i.e. in df in this example.
item={'colx':['a','b','a','c']}
df=pd.DataFrame(item)
df
colx
0   a
1   b
2   a
3   c
df['row_count']=1
df.groupby(['colx'])['row_count'].sum().reset_index()
colx    row_count
0   a   2
1   b   1
2   c   1
 
     
     
    