group by count dataframe

df.groupby(['col1', 'col2']).size().reset_index(name='counts')

Here is what the above code is Doing:
1. We’re using the groupby method to group the dataframe by the columns col1 and col2.
2. We’re using the size method to count the number of rows in each group.
3. We’re using the reset_index method to reset the index of the resulting dataframe.
4. We’re using the name parameter to name the column counts.