[英]How can I read and process part of file and write the rest to another file?
[英]How can I read part of file and write the rest to another file?
我有多个大型csv文件。 如何读取每个文件的一部分并将10%的数据/行写入另一个文件?
这对我有用:
with open("in.csv") as infile, open("out.csv", "w") as outfile:
outcsv = csv.writer(outfile)
for i, row in enumerate(csv.reader(infile)):
if not i % 10:
outcsv.writerow(row)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.