I have a pandas DataFrame, and one column’s values that I want to use are lists. I want to combine two elements one by one of each list, and output into another DataFrame.
For example, I have dataframe df, which contains col_a and col_b. The values of col_b are lists. I want to loop values of df.col_b, output a paired lists.
import pandas as pd
df=pd.DataFrame({'col_a':['ast1','ast2','ast3'],'col_b':[['text1','text2','text3'],['mext1','mext2','mext3'],['cext1','cext2']]})
df
col_a col_b
0 ast1 [text1, text2, text3]
1 ast2 [mext1, mext2, mext3]
2 ast3 [cext1, cext2]
I want this:
col_a col_b_1
0 ast1 [text1, text2]
1 ast1 [text1, text3]
2 ast1 [text2, text3]
3 ast2 [mext1, mext2]
4 ast2 [mext1, mext3]
5 ast2 [mext2, mext3]
6 ast3 [cext1, cext2]