元组到 pandas 数据框列表的列表

问题描述:

我有这个数组(这是相似度计算的结果),它是一个像这样的元组列表:

I have this array (it's a result from similarity calcul) it's a list of tuples like this:

example = [[(a,b), (c,d)], [(a1,b1), (c1,d2)] …]

例如,有121044个列表,每个列表包含30个元组.

In example there is 121044 list of 30 tuples each.

我想要一个像元组的第二个值(即b,d,b1,d2)那样的熊猫数据框,而又不花很多时间计算它

I want to have a pandas Dataframe like of just the second value of the tuples (i.e : b, d, b1, d2) without spending to much time compute it

您有什么想法吗?

使用嵌套列表理解:

df = pd.DataFrame([[y[1] for y in  x] for x in example])
print (df)
    0   1
0   b   d
1  b1  d2


df = pd.DataFrame([[y[1] for y in  x] for x in example], columns=['col1','col2'])
print (df)
  col1 col2
0    b    d
1   b1   d2