Created
July 24, 2020 05:04
-
-
Save yeiichi/0471d165e3a3824035c27d90906e0072 to your computer and use it in GitHub Desktop.
Convert a json dict to a flat csv.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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