将json的文本文件转换为csv文件

import pandas as pd
import fire
import glob
import json

def text_to_csv(file_name):
    json_data = json.load(open(file_name, 'r'))
    df = pd.read_json(json_data)
    df.to_csv(file_name[:-3] + 'csv')

def main(dir):
    dir = dir.replace("\\", "/")
    file_paths = glob.glob(dir + "/*.txt")
    for fp in file_paths:
        print("file_path:" + fp)
        text_to_csv(fp)

if __name__ == ‘__main__’:
    fire.Fire()

转载于:https://www.cnblogs.com/everfight/p/json_to_csv.html

你可能感兴趣的:(将json的文本文件转换为csv文件)