lst = [{"a": 1, "b": 1}, {"a": 2, "b": 2},{"a": 3, "b": 3},{"a": 3, "b": 3}] 比如这样
1
liwufan 2018-09-27 21:33:10 +08:00
|
2
fangdingjun 2018-09-27 21:34:33 +08:00 via Android
英文逗号分隔,中文要编码成 gbk
|
3
xpresslink 2018-09-27 22:54:51 +08:00
>>> import csv
>>> f = open('d:/tmp/test.csv', 'w', encoding='gbk') >>> writer = csv.DictWriter(f, fieldnames=['a','b']) >>> for dic in [{"a": 1, "b": 1}, {"a": 2, "b": 2},{"a": 3, "b": 3},{"a": 3, "b": 3}]: writer.writerow(dic) 5 5 5 5 >>> f.close() >>> |
4
lazyload 2018-09-28 10:33:27 +08:00
import pandas as pd
from pandas import DataFrame lst = DataFrame([{"a": 1, "b": 1}, {"a": 2, "b": 2},{"a": 3, "b": 3},{"a": 3, "b": 3}]) lst.to_csv('test.csv') |