2016-08-16 23 views
0

以下のコードを使用すると、データはエクスポートされますが、すべてが1つの列にまとめられます。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) 
+0

[ファイルへのPythonの輸出のcsvデータ]の可能な重複(http://stackoverflow.com/questions/18813490/python-export-csv-data-into -file) – Cyrbil

+0

'strList'はどこに定義されていますか?また、サンプルデータが役立ちます。 – Alexander

+0

'strList'とは何ですか?これは行の集合( '['r1'、 'r1c2']、['r2'、 'r2c2']]')でなければなりません。 –

答えて

0

あなたのデータが与えられていると、データが実際にこのように見える場合を除き、私はこのことがどのように間違っているのか分かりません。

>>> 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): 
関連する問題