Skip to content

Instantly share code, notes, and snippets.

@yeiichi
Created July 24, 2020 05:04
Show Gist options
  • Save yeiichi/0471d165e3a3824035c27d90906e0072 to your computer and use it in GitHub Desktop.
Save yeiichi/0471d165e3a3824035c27d90906e0072 to your computer and use it in GitHub Desktop.
Convert a json dict to a flat csv.
import json
import pandas as pd
def json2csv(file_path):
with open(file_path) as f:
my_dict = json.load(f)
df = pd.DataFrame.from_dict(my_dict, orient='index')
df.to_csv(file_path+'.csv')
print('DONE!')
if __name__ == '__main__':
file_path = input('File path(foo.json)? >> ')
json2csv(file_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment