首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pandas数据帧的多行列表

pandas数据帧的多行列表
EN

Stack Overflow用户
提问于 2020-06-15 03:54:26
回答 1查看 57关注 0票数 0

我正在尝试将多行列表转换为pandas df。通过解析键值,从多个json文件创建每个列表。这是它看起来的样子。

代码语言:javascript
复制
['Hello', 'This', 'Is', 'a', '', '95', 'ML', 'file', 'that', 'needs', 'tobe', 'parsed', 'and','all the paragraph', 'should', 'be','captured' 'for','comp1']
['hi', 'This', 'line', 'a', '', '100', 'ML', 'file', 'that', 'needs', 'tobe', 'parsed', 'and','all the paragraph', 'should', 'be','captured' 'for','comp222222']

当我转换它时,每一行都变成了一个索引,但实际上每个列表都应该是一个索引。在这种情况下,索引0和index1。它会像这样,

代码语言:javascript
复制
    colname=text
0 Hello This Is a  95..
1 hi This line a ....

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2020-06-15 04:03:28

代码语言:javascript
复制
l1 = ['Hello', 'This', 'Is', 'a', '', '95', 'ML', 'file', 'that', 'needs', 'tobe', 'parsed', 'and','all the paragraph', 'should', 'be','captured', 'for','comp1']
l2 = ['hi', 'This', 'line', 'a', '', '100', 'ML', 'file', 'that', 'needs', 'tobe', 'parsed', 'and','all the paragraph', 'should', 'be','captured', 'for','comp222222']

all_lists = [l1, l2]

df = pd.DataFrame([{'Text': ' '.join(l)} for l in all_lists])
print(df)

打印:

代码语言:javascript
复制
                                                Text
0  Hello This Is a  95 ML file that needs tobe pa...
1  hi This line a  100 ML file that needs tobe pa...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62377513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档