I have a column A and a column B. In column Result I would like to calculate the mean of column B grouped by column A (which means I would like to calculate what I wrote into the column Result).
cor = pd.DataFrame({'A' : [100, 100, 100, 200, 200, 300, 300, 300, 300],
'B' : [10, np.NaN, 20, np.NaN, 50, 10, 40, 60, 80],
'Result': [15, 15, 15, 50, 50, 47.5, 47.5, 47.5, 47.5]})
print(cor)
values = cor.groupby('A').mean()
In my dataset I have about 200k rows of data, so the function should be quite powerfull.