There is a df - DataFrame pandas. It has two columns. In the column "A" is a variable, in the column "B" is a class label.
How to replace the values in the column "A" by the average values for the corresponding class?
It’s easy to calculate the mean values themselves:
df.groupby('B')['A'].mean() But now how to replace all the values in the "A" column with the calculated averages?