I have a sample dataframe:
data = {'IDs': ['1', '1', '2', '2', '3', '3', '3', '4', '4', '5', '5'],
'Terms': ["a", "b", "a", "d", "c", "f", "g", "a", "h", "i", "j"],
'Values': [100, 100, 200, 200, 300, 300, 300, 400, 400, 500, 500]
}
df = pd.DataFrame(data, columns = ['IDs', 'Terms', 'Values'])
Which creates this:
I want something that looks like the following table, where for each ID, the Terms underneath are mapped to the other terms within its ID with its respective value (I dont need both directions).
I really dont know where to start. I have tried looking at contigency tables, but nothing really looks like what I have. Any suggestions are really welcome.
question from:
https://stackoverflow.com/questions/65905449/create-dataframe-of-relationships-per-id-from-to 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…