How to unnest (explode) a column in a pandas DataFrame?
I believe this question is not a duplicate of the one listed above. I am trying to find the combination of the cells in a column and create two columns out of this. The above explanation shows how to un-nest a list, but not find the combinations of that list...
I have a dataframe where one of the columns contains a list. I am trying to expand this dataframe so that I can get every combination of the list and still keep the other info. Hard to explain, example dataframes below:
name number ID code
1111 2 3 ['%AB','$12','&FD']
I am trying to figure out how to turn this dataframe into the following:
name number ID to from
1111 2 3 %AB $12
1111 2 3 %AB &FD
1111 2 3 $12 &FD
code I tried:
a = [y for x in df[['code']].stack() for y in combinations(x,2)]
df[['to','from']] = a