Reputation: 2417
I have a bunch of data that I need to transform, but I don't know the best way to go about it, so I was hoping to get some help here.
The data that I've collected (and I've got a lot of it) consists of a single line for each time a person has attended an event.
user A -- event 1
user B -- event 1
user B -- event 2
user C -- event 2
user D -- event 2
I would like to transform the data to instead show me the relationships of people who attended events together.
user A -- user B -- event 1
user A -- user B -- event 2
user A -- user C -- event 2
user B -- user C -- event 2
Hopefully I've provided enough description to understand the requirements. Thank you for your insight on the best way to tackle this problem.
Upvotes: 0
Views: 157
Reputation: 194
Use a dictionary and have event as your key and use use an array of users as your value. For every event you hit in the data, push the user to the array. so your dictionary structure would look like this.
user_event = {
'1' : ['A', 'B', 'C'],
'2' : ['B', 'C'],
'3' : ['A', 'B', 'D'],
'4' : ['C', 'D']
}
From this you can make your pairings
Upvotes: 2