简体   繁体   English

我有一个csv文件,我想将csv文件的每一行提取到不同的csv文件中。 我怎样才能做到这一点?

[英]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.

相关问题 我有一个csv文件,想提取一列并将int作为数组 - I have a csv file and want to extract a column and strore int as array 如何将每一行写入 csv 文件? - How can I write each row to a csv file? 我有不同的zip文件,每个文件包含一个csv文件。 如何解压缩每个文件夹,并将所有csv文件保存在一个文件夹中 - I have different zip files that contain one csv file each. how do I unzip each folder, and save all the csv files in one folder 如何将 CSV 文件行放入我构建的表中? - How do I take a CSV file row into a table that I built? 如何提取整个表格并将其存储在 CSV 文件中? - How do I extract entire table and store it in CSV file? 如何快速从大量的csv文件提取数据? - How do I quickly extract data from this massive csv file? 我有三个列表,我想创建一个 csv 文件 - I have three lists and I want to create a csv file 如何从 Python 中的 CSV 文件中提取 JSON 对象? - How can I extract a JSON object from a CSV file in Python? 我有大量的csv文件,我想在字典中读取它,然后将字典再次写入新的csv文件中, - i have bulk csv file i want to read it in dictionary then write the dictionary again into new csv file , 如何使用 python 将 csv 文件中的每 7 行转换为单行? - How can I transform each 7 row to single row in csv file with python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM