如何将高维元组列表转换为数据帧?
我有一个表格,从中获取嵌入数据,它以包含 3000 个数字的元组形式包含在 Embedding 列中。现在,我必须将这些嵌入的索引映射到我的数据集。我使用此代码进行上述操作:
p_x = [p_embedding[p_embedding['p_id'] == int(pid)]['Embedding'] for pid in p_mapping]
编辑:添加示例数据 编辑2:大小为300
p_embedding
,元组大小为300:
p_id embedding
100 (0.11757241, -0.23792185, 0.30370793...)
101 (-0.1045902, 0.27551234, -0.15883833...)
102 (-0.0038427562, 0.091357835, -0.029324641...)
带有索引映射的p_mapping
:
{'100': 0,
'101': 1,
'102': 2}
这为我提供了我想要的包含正确顺序嵌入的列表,但它是仍然是一列元组的形式。前三行如下所示:
[Series([], Name: Embedding, dtype: object),
2463 (-0.080065295, 0.085681394, 0.044956923, 0.078...
Name: Embedding, dtype: object,
2510 (0.19006088, 0.1552349, -0.028743511, -0.25197...
Name: Embedding, dtype: object,
我想将此元组拆分为数据帧的单独列,但是当我执行 pd.DataFrame 时,我只得到包含所有 NAN 值的 3000 多列的 DF。这背后有什么原因吗?我必须更改列表的索引吗?
I have a table from where I am getting my embedding data, it's contained in the Embedding
column in the form of tuples having 3000 numbers. Now, I have to map the index of these embeddings to my dataset. I am using this code for the above:
p_x = [p_embedding[p_embedding['p_id'] == int(pid)]['Embedding'] for pid in p_mapping]
Edit: Adding sample data
Edit 2: Size is 300
p_embedding
with tuple of size 300:
p_id embedding
100 (0.11757241, -0.23792185, 0.30370793...)
101 (-0.1045902, 0.27551234, -0.15883833...)
102 (-0.0038427562, 0.091357835, -0.029324641...)
p_mapping
with index mappings:
{'100': 0,
'101': 1,
'102': 2}
This gives me the list that I want containing the embeddings in the correct order, but it's still in the form of a tuple in one column. The first three rows are like this:
[Series([], Name: Embedding, dtype: object),
2463 (-0.080065295, 0.085681394, 0.044956923, 0.078...
Name: Embedding, dtype: object,
2510 (0.19006088, 0.1552349, -0.028743511, -0.25197...
Name: Embedding, dtype: object,
I want to split this tuple into separate columns of a dataframe, but when I do pd.DataFrame
I just get a DF of 3000+ columns with all NAN values. Is there any reason behind this, do I have to change the index of the list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
给出:
Try this:
which gives: