Skip to content

Instantly share code, notes, and snippets.

@besendorf
Created March 1, 2022 09:32
Show Gist options
  • Save besendorf/9789bbd713f1fa3d4d9acd18be246973 to your computer and use it in GitHub Desktop.
Save besendorf/9789bbd713f1fa3d4d9acd18be246973 to your computer and use it in GitHub Desktop.
convert MVT records from json to csv
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