Everfighting
5/2/2018 - 1:05 AM

convert json to csv

convert json to 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()