[英]I have a csv file and i want to extract each row of csv file into different csv file . how can i do that?
I have a CSV file and I want to extract each row of CSV file into the different CSV files. 我有一个CSV文件,我想将CSV文件的每一行提取到不同的CSV文件中。 how can I do that? 我怎样才能做到这一点?
Like this, it will be saved in files numerated by number of row 这样,它将保存在按行数编号的文件中
import csv
with open('file.csv', 'r') as csv_file:
rows = csv.reader(csv_file, skipinitialspace=True)
for i, row in enumerate(rows):
with open('file_{}.csv'.format(i), 'w') as write_file:
writer = csv.writer(write_file)
writer.writerow(row)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.