Counting weight of unique combinations within groups

I have the following dataframe:

    Group  from  to
     1      2    1
     1      1    2  
     1      3    2 
     1      3    1 
     2      1    4 
     2      3    1
     2      1    2
     2      3    1

I want create a 4th column that counts the of unique combinations (from, to) within each group and drops any repeated combination within each group (leaves only one)

Expected output:

    Group  from  to weight
     1      2    1     1
     1      1    2     1
     1      3    2     1
     1      3    1     1
     2      1    4     1
     2      3    1     2
     2      1    2     1
 

In the expected output, the 2nd from 3, to 1 row in group 2 was dropped because it is a duplicate.

Answer

In your case we just need groupby with size

out = df.groupby(df.columns.tolist()).size().to_frame(name='weight').reset_index()
Out[258]: 
   Group  from  to  weight
0      1     1   2       1
1      1     2   1       1
2      1     3   1       1
3      1     3   2       1
4      2     1   2       1
5      2     1   4       1
6      2     3   1       2