Thanks for the minimal but complete reproducible example.
In this case, after your initial setup code:
import pandas as pd
df = pd.DataFrame({'a': [0,0,2,2,3,3], 'b':[4,5,2,1,8,6]})
You can just use the transform method of the groupby object to get the means transformed back to the original, and assign the result back to a new column:
df['d'] = df.groupby('a').transform('mean')
This yields your desired result:
a b d
0 0 4 4.5
1 0 5 4.5
2 2 2 1.5
3 2 1 1.5
4 3 8 7.0
5 3 6 7.0
This Stack Overflow answer has more details:
(Optionally, if you want it assigned to a new dataframe instead of the original, like you did above, create it first with df1 = df.copy() on a line before this.)