Python 的 JSON 到 CSV

拉尼什·比扬卡

我知道这有很多问题,但我在处理数据时遇到了麻烦。

我有这个清单:

['2017-05-31,20:00:00,71.1,73,', '2017-05-31,20:05:00,71.1,72.7,', '2017-05-31,20:10:00,71.1,72.5,', '2017-05-31,20:15:00,71.1,72.4,']

我需要将此 JSON 格式转换为 CSV,其中 CSV 看起来像这样。

在此处输入图片说明

特罗尔德霍

我建议:

my_list = ['2017-05-31,20:00:00,71.1,73,', '2017-05-31,20:05:00,71.1,72.7,', '2017-05-31,20:10:00,71.1,72.5,', '2017-05-31,20:15:00,71.1,72.4,']
# create and open a file for writing
with open("my_file.csv", "w") as fout:
    # iterate through your list
    for element in my_list:
        # write your element in your file plus a \n to trigger a new line
        fout.write(element+"\n")

你去吧!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章