将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()
posted @ 2018-05-02 09:04  bingo彬哥  阅读(13058)  评论(0编辑  收藏  举报
本站总访问量