Let's say we have the following dataset:
import pandas as pd
data = [('apple', 'red', 155), ('apple', 'green', 102), ('apple', 'iphone', 48),
('tomato', 'red', 175), ('tomato', 'ketchup', 96), ('tomato', 'gun', 12)]
df = pd.DataFrame(data)
df.columns = ['word', 'rel_word', 'weight']
I would like to recompute weights, so that they sum up to 1.0 within each group (apple, tomato in the example) and keep related weights as is (e.g. apple/red to apple/green still should be 155/102).
