小编ser*_*ade的帖子

在 Python 中将 zip 列表保存到 csv

我如何将下面的 zip 列表写入 python 中的 csv 文件?

[{'date': '2015/01/01 00:00', 'v': 96.5},
 {'date': '2015/01/01 00:01', 'v': 97.0},
 {'date': '2015/01/01 00:02', 'v': 93.75},
 {'date': '2015/01/01 00:03', 'v': 96.0},
 {'date': '2015/01/01 00:04', 'v': 94.5}
Run Code Online (Sandbox Code Playgroud)

我有这个错误:

_csv.Error: sequence expected
Run Code Online (Sandbox Code Playgroud)

我的代码在这里:

import csv
res = zip_list
csvfile = "/home/stm/PycharmProjects/isbak_trafik/example.csv"

with open(csvfile, "w") as output:
    writer = csv.writer(output, lineterminator='\n')
    writer.writerows(res)
Run Code Online (Sandbox Code Playgroud)

python csv export zipfile export-to-csv

5
推荐指数
1
解决办法
4734
查看次数

加载 IPython Jupyter 笔记本时出错:

加载 IPython Jupyter 笔记本时出错。外壳上也会发生错误。有没有人可以帮助我解决这些错误?


发生在外壳上的错误:

Unhandled error in API request
DatabaseError: database disk image is malformed
Run Code Online (Sandbox Code Playgroud)

加载 Jupyter 笔记本时出错:

An unknown error occurred while loading this notebook. 
This version can load notebook formats v4 or earlier. See the server log for details.
Run Code Online (Sandbox Code Playgroud)

python diskimage ipython malformed jupyter

4
推荐指数
1
解决办法
3657
查看次数

值错误:对象对于所需数组的深度太小

我想关联 zip_list 中的 s1 和 s2 变量。但是,我有这个错误:

“返回 multiarray.correlate2(a, v, mode) ValueError:所需数组的深度太小的对象”

有没有人可以帮助我?


s1 = [] 
s2 = []
date = []

for f in files:
    with open(f) as f:
    f.next()
    rows = csv.reader(f)
    for row in rows:
        item_list = []
        for row_item in row:
            output_string = map(lambda x: '0' if x=='NULL' else x, row_item.split(","))
            item_list.append(output_string)
        date = item_list[0]
        s1 = item_list[2]
        s2 = item_list[3]

        zip_list = []
        for x, y in zip(s1, s2):
            pos = {"s1": x, "s2": y} …
Run Code Online (Sandbox Code Playgroud)

python arrays correlation

2
推荐指数
1
解决办法
2万
查看次数