Hi Hoping to get some help, I have two columns Dataframe df
as;
Source ID
1 2
2 3
1 2
1 2
1 3
3 1
My intention is to group the Source and divide the ID cell by total based on the grouped Source and attach this to the orginial dataframe so the new column would look like;
Source ID ID_new
1 2 2/9
2 3 3/3
1 2 2/9
1 2 2/9
1 3 3/9
3 1 3/1
I've gotten as far as;
df.groupby('Source ID')['ID'].sum()
to get the total for ID
but Im not sure where to go next.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…