简体   繁体   English

从python导出数据到csv

[英]Export data from python to csv

I want to do some calculations with python and export the data afterwards into a csv file.我想对 python 进行一些计算,然后将数据导出到 csv 文件中。 This works fine.这很好用。 But it writes everything into the same cell.但它将所有内容写入同一个单元格。 So, I wanted to ask if it is possible to do the same just write every value in a cell.所以,我想问问是否可以做同样的事情,只需将每个值都写在一个单元格中。 The way I export is the code below:我导出的方式是下面的代码:

import csv

f = open('C:///Users///....csv', 'a', newline='')

row = [x, y,z]

writer = csv.writer(f)

writer.writerow(row)
f.close

Like this I get one cell with the value [x,y,z], but I would like to have each of x,y,z in a seperate cell.像这样,我得到一个值为 [x,y,z] 的单元格,但我想将 x、y、z 中的每一个都放在一个单独的单元格中。

import csv
row = [x, y,z]
with open("C:///Users///....csv", mode='a') as file:
    writer = csv.writer(file)
    writer.writerow(row)

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

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