Created
May 28, 2021 13:40
-
-
Save larsyencken/ab81fb05872f04ffc52a6e609cfb8a72 to your computer and use it in GitHub Desktop.
OWID: shrink Covid JSON by changing JSON representation of data
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
#!/usr/bin/env python | |
import pandas as pd | |
import json | |
INPUT_FILE = "owid-covid-data.json" | |
OUTPUT_FILE = "owid-covid-data-list.json" | |
with open(INPUT_FILE) as istream: | |
data = json.load(istream) | |
def remap_country(c): | |
c = c.copy() | |
df = pd.DataFrame.from_dict(c["data"]) | |
c["data"] = df.to_dict(orient="list") | |
return c | |
new_data = {key: remap_country(c) for key, c in data.items()} | |
with open(OUTPUT_FILE, "w") as ostream: | |
json.dump(new_data, ostream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment