简体   繁体   中英

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. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM