Goal is to get average(integer) of marks column based on name value. If id and name column appears with exact same value more than once, then the marks with corresponding name will be considered once. For e.g. average of x = (33+14+3)/3 = 16
Sample dataframe:
id name marks
0 1 x 33
1 1 x 33
2 2 y 9
3 3 x 14
4 4 y 55
5 4 y 55
6 5 x 3
7 6 z 31
Expected output:
id name marks avg
0 1 x 33 16
1 1 x 33 16
2 2 y 9 32
3 3 x 14 16
4 4 y 55 32
5 4 y 55 32
6 5 x 3 16
7 6 z 31 31
I tried:
df["avg"] = df.groupby("name")["marks"].mean()