我正在尝试将多行列表转换为pandas df。通过解析键值,从多个json文件创建每个列表。这是它看起来的样子。
['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。它会像这样,
colname=text
0 Hello This Is a 95..
1 hi This line a ....谢谢你的帮助。
发布于 2020-06-15 04:03:28
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)打印:
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...https://stackoverflow.com/questions/62377513
复制相似问题