json 转 csv

json 转 csv


import pandas as pd
import json

file_path = "country_2.json"
with open(file_path, encoding='utf-8') as file_obj:
    lines = file_obj.readlines()
    dict_lines = [json.loads(line) for line in lines] # 字符串转json
    data_frame = pd.DataFrame(dict_lines).to_csv("output.csv", encoding="utf-8", index=False) # 输出CSV文件的时候不加索引
    pass

你可能感兴趣的:(python)