我想删除90%,其中有“转向”价值QUAL为0并且对于所有三架F其中,中心相应的图像文件行,左,右的。我也想删除它们。 csv文件是这样的:删除特定行和相应的文件在python
我写了下面的代码,至少得到的文件有转向价值0.我所需要的是随机获得这些文件的90%,并删除它们的代码。
with open('data/driving_log.csv') as csvfile:
reader = csv.reader(csvfile)
for i,line in enumerate(reader):
lines.append(line)
index.append(i)
lines = np.delete(lines,(0), axis = 0)
for i, line in enumerate(lines):
#print(type(line[3].astype(np.float)))
line_no.append(line[3].astype(np.float32))
#print(line_no[i])
if line_no[i]==0.0:
# this gets the first column of the row.
for j in range(3):
source_path = line[j]
filename = source_path.split('/')[-1]
print(filename)
count += 1
你有搜索如何生成随机数和在Python删除文件? [产生随机数(http://stackoverflow.com/questions/3996904/generate-random-integers-between-0-and-9)。 [删除文件(http://stackoverflow.com/questions/6996603/how-to-delete-a-file-or-folder)。 –
是的,我需要导入随机并使用os.remove()删除文件。但是,我越来越感到困惑在两个地方,移除一行形成csv文件,并随机删除具有转向值等于0 –
您可以发布文本格式的CSV文件的部分文件的90%?最好用逗号作为分隔符。 –