I have 2 dataframes from the following
df :
Name
1 A
2 B
3 C
4 C
5 D
6 D
7 D
8 D
and df_value :
Name Value
1 A 50
2 B 100
3 C 200
4 D 800
I want to merge both dataframes (into df), but with the new Value being worth the df_value Value divided by the number of occurences of Name in df
Output :
Name Value
1 A 50
2 B 100
3 C 100
4 C 100
5 D 200
6 D 200
7 D 200
8 D 200
A appears once, has a Value of 50 in df_value, so its value is 50. Same logic for B.
C appears 2 times, has a value of 200 in df_value, so its value is 200 / 2 = 100
D appears 4 times, has a value of 800 in df_value, so its value is 800 / 4 = 200
I'm pretty sure there's a really easy way to do that but I can't find it. Thanks in advance.