簡體   English   中英

將數據導出到CSV python

[英]Exporting data to csv python

當我在下面使用以下代碼時,我的數據將被導出,但所有數據都將一直列在下面,有什么幫助嗎?

b = open('tester.csv', 'wb')
a = csv.writer(b)
while (count < x):
    tags = str(data['alerts'][count]  ['tags']).replace("u\"","\"").replace("u\'","\'")
a.writerows(strList)  

給定您的數據,除非您的數據實際上看起來不是這樣,否則我看不到這怎么可能出錯。

>>> data = [['hi', 'yes', 'bye', 'def'], ['hi', 'ast', 'cnx', 'vplex'], ['ever', 'as', 'no', 'qwerty', 'redi'], ['no', 'yes', 'qwerty'], ['redi', 'google'], ['redi', 'asdf', 'asdfef', 'wer'], ['redi', 'asd', 'rrr', 'www', 'qqq'], ['erfa', 'asdf', 'fef'], ['hi', 'dsa', 'f3e']]
>>> with open('my.csv','w') as f:
...  for item in data:
...   my_item = item[0]+','+item[1]+'\n'
...   f.write(my_item)
... 

pg my.csv

hi,yes
hi,ast
ever,as
no,yes
redi,google
redi,asdf
redi,asd
erfa,asdf
hi,dsa
(EOF):

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM