【问题标题】:How to write the data converted from json to csv without skipping the rows如何在不跳过行的情况下写入从 json 转换为 csv 的数据
【发布时间】:2019-08-14 15:47:36
【问题描述】:

我已将 json 转换为 csv。问题是当我将 json 内容写入 csv 时,在 excel 中数据以交替行出现

我一直使用的代码是:

with open(name_j,'r',encoding='utf8') as data_file:
    data = json.loads(data_file.read())


with open('../json_to_csv/Data/Output/Output.csv', 'w',encoding='utf8') as csv_file:
    writer = csv.writer(csv_file)

    writer.writerow(['doi', 'is_oa', 'title', 'publisher','z_authors','journal_name' ])
    #writer.writerow(['doi','title', 'publisher','journal_name'])

    for row in data:
        doi = row['doi']
        oa = row['is_oa']
        name = row['title']
        pub = row['publisher']
        author = row['z_authors']
        jName = row['journal_name']

        row = [doi, oa, name, pub, jName]
        #row = [doi, name, pub, jName]

        writer.writerow(row)

Final csv result 如何写而不跳过行。

【问题讨论】:

    标签: json python-3.x csv


    【解决方案1】:

    您需要做的只是对代码稍作改动:

    with open('../json_to_csv/Data/Output/Output.csv', 'w',encoding='utf8', newline='') as csv_file:
        writer = csv.writer(csv_file)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      • 2020-03-15
      相关资源
      最近更新 更多