Having the following dataset:
+-----+-----+-----+
|col1 |col2 |score|
+-----+-----+-----+
|"A" |"B" |6 |
+-----+-----+-----+
|"A" |"B" |4 |
+-----+-----+-----+
|"C" |"D" |4 |
+-----+-----+-----+
|"C" |"D" |3 |
+-----+-----+-----+
I'm grouping by col1 and col2 and getting the mean like so()
df.groupby(['col1','col2']).mean()
Now I want to distribute the mean result to each of the group rows and replace the score coliumn, to get:
+-----+-----+-----+
|col1 |col2 |mean |
+-----+-----+-----+
|"A" |"B" |5 |
+-----+-----+-----+
|"A" |"B" |5 |
+-----+-----+-----+
|"C" |"D" |3.5 |
+-----+-----+-----+
|"C" |"D" |3.5 |
+-----+-----+-----+
How can I do it?