简体   繁体   English

将多个输入CSV文件中的数据以列格式写入单个CSV中

[英]Write data from multiple input CSV file to a single CSV in column format

I'm trying to 我试图

  • loop over multiple csv files, 循环多个csv文件,

  • extract information from them 从他们那里提取信息

  • write an output into one new csv file with a row for each of the original files. 将输出写入一个新的csv文件,每个原始文件一行。

I take the information: 我得到的信息是:

Name, Date, Time, Test, Navg, Percent 名称,日期,时间,测试,导航,百分比

for each row. 每行。

I have tried to do it, however I have the problems: 我已经尝试过这样做,但是有一些问题:

  1. It writes each of Name, Date, Time, Test, Navg, Percent to a NEW ROW...I want each word in a new column 它将名称,日期,时间,测试,导航,百分比中的每一个写入新行...我希望每个单词都在新列中
  2. It writes each new file to the a new row underneath(I do want it underneath, but with each word in a column. 它将每个新文件写到下面的新行中(我确实希望它在下面,但每个单词都在列中。

     b = open('C:\\Users\\AClayton\\Desktop\\Data.csv', 'a') a = csv.writer(b,delimiter='\\t',lineterminator='\\n') a.writerows((Name, Date, Time, Test, Navg, Percent)) b.close() 

Note the file has been read and the data extracted in earlier code. 请注意,文件已被读取,数据已在较早的代码中提取。

writerows interpretes the input argument as a list of rows, hence each item in your tuple is written into a separate row. writerows将输入参数解释为行列表,因此元组中的每个项目都被写入单独的行中。 Using writerow should write it into a single row. 使用writerow应该将其写入一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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