【发布时间】:2021-08-22 00:52:22
【问题描述】:
我正在尝试处理一个巨大的 .csv 文件,但我不需要前约 900000 行数据。这就是我最初试图摆脱那块数据的方式,但它使程序需要很长时间才能完成。有没有更直接的方法可以做到这一点,我什至一开始都不读取前 900000 行?
firstColumn = [ ]
secondColumn = [ ]
thirdColumn = [ ]
readFile = input("Enter name of file to be read: ")
with open(readFile,'r') as readFile:
for eachline in readFile: # converting columns to lists
parts = eachline.strip('\n').split(',')
firstColumn.append(parts[0])
secondColumn.append(parts[1])
thirdColumn.append(parts[2])
for j in range(900000): # nothing happens for these datapoints
del firstColumn[j]
del secondColumn[j]
del thirdColumn[j]
【问题讨论】:
-
与 Spyder IDE 有什么关系?请只添加相关标签。