Let's say I have something like this:
df = pd.DataFrame({'key':[1,2,3], 'type':[[1,3],[1,2,3],[1,2]], 'value':[5,1,8]})
key type value
1 [1, 3] 5
2 [1, 2, 3] 1
3 [1] 8
Where one of the columns contains a list of items. I would like to create several rows for each row that contains multiple types.
Ontaining this:
key type value
1 1 5
1 3 5
2 1 1
2 2 1
2 3 1
3 1 8
I've been playing with apply with axis=1 but I can't find a way to return more than 1 row per row of the DataFrame. Extracting all different 'types' and then looping-concatenating seems to be ugly.
any ideas? Thanks!!!