Skip to content

Instantly share code, notes, and snippets.

@larsyencken
Created May 28, 2021 13:40
Show Gist options
  • Save larsyencken/ab81fb05872f04ffc52a6e609cfb8a72 to your computer and use it in GitHub Desktop.
Save larsyencken/ab81fb05872f04ffc52a6e609cfb8a72 to your computer and use it in GitHub Desktop.
OWID: shrink Covid JSON by changing JSON representation of data
#!/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