2

I have a dataframe of nested lists, with each list having a number of 2-element-lists nested within, looks like follows:

l1 = [[[1,0]],[[1,2],[6,9]],[[0,4]],[[0,4]], [[0,4]]]
l2 = [[[1,0]],[[1,2],[6,9]],[[0,4]],[[0.5]], [[0,6]]]
df_test= pd.DataFrame({'lst1Title': l1,
     'lst2Title': l2})
df_test 

enter image description here

What I am trying to do is to get the repeated entities under 1st1Title found and the corresponding outputs rows in column lst2Title grouped, and power list (possible permutations wihtout repetition) of 2 element lists generated, and repeated for each - as reproduced and shown bellow:

l1 = [[[1,0]],[[1,2],[6,9]],[[0,4]],[[0,4]], [[0,4]]]
l2 = [[[1,0]],[[1,2],[6,9]],[[0,4]],[[0.5]], [[0,6]]]
l3 = [[[1,0]],[[1,2],[6,9]],[[0,4],[0,5],[0,6],[4,5],[4,6],[5,6]],[[0,4],[0,5],[0,6],[4,5],[4,6],[5,6]], [[0,4],[0,5],[0,6],[4,5],[4,6],[5,6]]]
df_test= pd.DataFrame({'lst1Title': l1,
     'lst2Title': l2, 'output': l3})

enter image description here

Ive tried variations of pd.groupby, which was consistently faced with 'list not hashable' error, as well as itertools.groupby, so far no luck.

 pd.DataFrame([list(g) for k, g in itertools.groupby(df_test['1stTitle'])])

The number of elements in each column may change (i.e. row 1 in df)test has 2 lists, each with 2 elements) however each core element will always have 2 elements only, or be []. The core lists also dont have repeated numbers, i.e. [4,4] cannot exist.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.