Efficient Dataframe Transformation
So the question is count the number of duplications by user ID and other variables. 
For this you can use the df.groupby().size() method. This will return the counts of unique entries in with a particular value in a column.

Here is the documentation for this function: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html