我有一个读取 3GB 大数据文件的脚本,我不需要所有数据,如果满足条件,我想跳过特定的数据行。是否有 Python 函数可以跳过数据文件中的一行数据并继续读取文件?我检查了 3.2 文档,但只找到了一个跳过数据块的函数。
编辑
读入这样的数据
def read_file(F): #Function that reads data froma file
#and extracts specific data columns
X = []
Y = [] # Creats Data Lists
Z = []
N = 11912639 # number of lines to be read
f = open(F) #Opens file
f.readline() # Strips Header
nlines = islice(f, N) #slices file to only read N lines
for line in nlines: #Loop Strips empty lines as well as replaces tabs with space
if line !='':
line = line.strip()
line = line.replace('\t',' ')
columns = line.split()
x = columns[0] # assigns variable to columns
y = columns[1]
z = columns[2]
X.append(x)
Y.append(y) #appends data in list
Z.append(z)
我想做的是在上面的代码中添加一个 if 语句,例如
if x > somevalue:
skipline
else:
continue