I have the following DF:
DATE TEAM PTS MEAN_PTS
1-1-2015 x 50 1?
1-1-2015 y 60 2?
2-1-2015 x 70 3?
2-1-2015 y 80 4?
I'm want the columns MEAN_PTS to be mean value of the pass PTS column based on the team. Like, 1? should be 50, 2? should be 60, 3? should be 60, 4? should be 70
I tried something like that:
DF['MEAN_PTS'] = 0
for i in range(0, len(DF)):
cont = 1
for line in range(0, len(DF)):
if line != i:
if DF.loc[line, 'TEAM'] == DF.loc[i, 'TEAM']:
cont += 1
DF[line, 'MEAN_PTS'] = (DF[line, 'PTS'] + DF[i, 'MEAN_PTS']*(cont-1)) / cont
But it dosent work. Return: Can only compare identically-labeled Series objects