我有兩個來自一個實驗的大型文本數據文件,我想用特殊方式將它分割成一個文件。Python - 結合文本文件(特定行)
數據的小樣本:
文件1:
plotA 10
plotB 9
plotC 9
文件2:
98%
7/10
21
98%
5/10
20
98%
10/10
21
而且我想結果是這樣的:
plotA 10 98% 7/10 21
plotB 9 98% 5/10 20
plotC 9 98% 10/10 21
我不知道它如何在python中解決。我試圖重新排序文件2具有:
lines = file2.readlines()
aaa = lines[0] + lines[3] + lines[6]
bbb = lines[1] + lines[4] + lines[7]
ccc = lines[2] + lines[5] + lines[8]
,並使用拉鍊,但我失敗了(這方法耗時大的文本文件)。
任何幫助?
引發'TypeError sequence item 1:expected string,tuple found',因爲z中的行是一個嵌套元組,例如, '('plotA 10 \ n',('98%\ n','5/10 \ n','20 \ n'))' –
@AndyKubiak這是編輯前的帖子,多年前已經編輯過; - ) – Kasramvd
是的,看到你的編輯。幾乎到了那裏。想象一下,我會放下一個格式化的櫻桃頂部爲雅。 –