Questions tagged «tab-delimited-text»

1
读取并解析TSV文件,然后对其进行处理以保存为CSV(*高效*)
我的源数据在一个TSV文件中,包含6列和超过200万行。 这是我要完成的工作: 我需要读取此源文件中3列(3、4、5)中的数据 第五列是整数。我需要使用此整数值来复制行条目,并使用第三和第四列中的数据(按整数倍)。 我想将#2的输出写入CSV格式的输出文件。 以下是我想到的。 我的问题:这是一种有效的方法吗?尝试进行200万行时,它似乎很密集。 首先,我制作了一个示例选项卡单独的文件以供使用,并将其命名为“ sample.txt”。它是基本的,只有四行: Row1_Column1 Row1-Column2 Row1-Column3 Row1-Column4 2 Row1-Column6 Row2_Column1 Row2-Column2 Row2-Column3 Row2-Column4 3 Row2-Column6 Row3_Column1 Row3-Column2 Row3-Column3 Row3-Column4 1 Row3-Column6 Row4_Column1 Row4-Column2 Row4-Column3 Row4-Column4 2 Row4-Column6 然后我有这段代码: import csv with open('sample.txt','r') as tsv: AoA = [line.strip().split('\t') for line in tsv] for a in …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.