元组到 pandas 数据框列表的列表 [英] List of list of tuples to pandas dataframe

查看:78
本文介绍了元组到 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

这篇关于元组到 pandas 数据框列表的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆