My data consists of messages between multiple people. I want to be able to add a column with a unique key that lets me link messages between two people as conversations. I can use the UUID module to generate the key so that's not a problem.
The tricky bit is that values in the "from" and "to" columns can be reversed as messages are sent in both directions.
My data looks like this:
df = pd.DataFrame({'From': [['1a2b3c', 'AAA'], ['4d5e6f', 'BBB'], ['7g8h9i', 'CCC'], ['111', 'ZZZ']],
'To': [['111', 'ZZZ'], ['222', 'YYY'], ['333', 'XXX'], ['1a2b3c', 'AAA']],
'Message': ['ABC', 'DEF', 'GHI', 'TEST']})
I would like my data to look like this (note the 1st and last rows are messages between the same person so have the same conversation key):
df = pd.DataFrame({'From': [['1a2b3c', 'AAA'], ['4d5e6f', 'BBB'], ['7g8h9i', 'CCC'], ['111', 'ZZZ']],
'To': [['111', 'ZZZ'], ['222', 'YYY'], ['333', 'XXX'], ['1a2b3c', 'AAA']],
'Message': ['ABC', 'DEF', 'GHI', 'TEST'],
'Conversation': ['6cbea588-356e-4b97-a950-a69469c652a9', 'c2c531da-a340-46a3-8290-e62488791bf7', '5723d816-04f4-4c6a-9870-239295c6d7ce', '6cbea588-356e-4b97-a950-a69469c652a9']})
Thanks :)!