Created
September 22, 2021 03:27
-
-
Save pekevski/02391e07a3fb67952bd2bbac4af51069 to your computer and use it in GitHub Desktop.
Convert a json file to csv in python
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
# pip install pandas | |
import pandas as pd | |
import sys | |
if len(sys.argv) is 2: | |
print(f'Error: 2 arguments required. Input file and output file. eg: to_csv.py file.json file.csv') | |
sys.exit() | |
input_file = sys.argv[1] | |
output_file = sys.argv[2] | |
print(f'Converting {input_file}...') | |
df = pd.read_json (input_file) | |
df.to_csv (output_file, index = None) | |
print(f'Success! Created {output_file}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment