Groupby.transform doesn't work in dask dataframe
I think you can use join
:
s = AID.groupby('AID')['ANumOfF'].sum()
AID = AID.set_index('AID').drop('ANumOfF', axis=1).join(s).reset_index()
print (AID)
AID FID ANumOfF
0 1 X 6
1 1 Y 6
2 2 Z 36
3 2 A 36
4 2 X 36
5 2 B 36
Or faster solution with map
by aggregate Series
or dict
:
s = AID.groupby('AID')['ANumOfF'].sum()
#a bit faster
#s = AID.groupby('AID')['ANumOfF'].sum().to_dict()
AID['ANumOfF'] = AID['AID'].map(s)
print (AID)
AID FID ANumOfF
0 1 X 6
1 1 Y 6
2 2 Z 36
3 2 A 36
4 2 X 36
5 2 B 36