大きなテキスト ファイル (10 MB の gzip) を処理しています。同じ長さと構造の 2 つのファイルが常に一緒に属します: データセットごとに 4 行。
両方のファイルから同時に、4 つのブロックごとに 2 行目のデータを処理する必要があります。
私の質問: これに対する最も時間効率の良いアプローチは何ですか?
今、私はこれをやっています:
def read_groupwise(iterable, n, fillvalue=None):
args = [iter(iterable)] * n
return itertools.izip_longest(fillvalue=fillvalue, *args)
f1 = gzip.open(file1,"r")
f2 = gzip.open(file2,"r")
for (fline1,fline2,fline3,fline4), (rline1, rline2, rline3, rline4) in zip(read_groupwise(f1, 4), read_groupwise(f2, 4)):
# process fline2, rline2
しかし、それぞれの行 2 しか必要ないので、おそらくこれを行うためのはるかに効率的な方法があると思いますか?