使用Python

时间:2018-06-07 13:11:43

标签: python-2.7

我有一个非常大的文本文件(.dat),我试图从中读取所选行。该文件有24列,我只想读取列nr 14中的值介于140和280之间的行,其中列nr 15中的值小于或等于50。

我对大文件的经验很少,但我认为必须有专门用于有效读取大文本文件的python模块和函数。有人知道怎么做吗?

以下代码是我想要做的(到目前为止我所拥有的)。虽然,我知道这个文本文件太大而无法使用np.loadtxt,所以我需要另一种方法。

import numpy as np
matrix_read = np.loadtxt('file.dat', dtype='float')
matrix_keep_col14 = matrix_read[:,13] >= 140 & <= 280    # Keep only rows where the value in column nr 14 is between 140 and 280
matrix_keep_col15 = matrix_keep_col14[:,14] <= 50    # Keep only rows where the value in column nr 15 is less than 50

0 个答案:

没有答案