Created
March 1, 2022 09:32
-
-
Save besendorf/9789bbd713f1fa3d4d9acd18be246973 to your computer and use it in GitHub Desktop.
convert MVT records from json to csv
This file contains 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 pandas as pd | |
import json | |
import os | |
filenames = next(os.walk('.'), (None, None, []))[2] | |
# read json | |
for filename in filenames: | |
if '.csv' in filename: | |
continue | |
if '.json' in filename: | |
print(filename) | |
with open(filename, 'r') as f: | |
data = json.load(f) | |
# create dataframe | |
df = pd.json_normalize(data) | |
#write .csv | |
df.to_csv(os.path.splitext(filename)[0] + '.csv', index=True, encoding='utf-8') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment