I want to create a dataframe from the owid covid19 json data located here. The json has an array of daily records in the data column, this along with the country index is what I'm trying to make into a dataframe.
{"AFG":{"continent":"Asia","location":"Afghanistan","population":39835428.0,"population_density":54.422,"median_age":18.6,"aged_65_older":2.581,"aged_70_older":1.337,"gdp_per_capita":1803.987,"cardiovasc_death_rate":597.029,"diabetes_prevalence":9.59,"handwashing_facilities":37.746,"hospital_beds_per_thousand":0.5,"life_expectancy":64.83,"human_development_index":0.511,"data":[{"date":"2020-02-24","total_cases":5.0,"new_cases":5.0,"total_cases_per_million":0.126,"new_cases_per_million":0.126,"stringency_index":8.33},{"date":"2020-02-25","total_cases":5.0,"new_cases":0.0,"total_cases_per_million":0.126,"new_cases_per_million":0.0,"stringency_index":8.33},
So far I've been loading the file straight into a dataframe
df = pd.read_json('owid-covid-data.json', orient='index')
and then normalizing the array as such
data = pd.concat([pd.DataFrame(json_normalize(key)) for key in df['data']])
Which works fine apart from dropping the index and thus giving no identifier to join back to the static values.
I also imagine there's a more efficient way of normalizing than what I've used.
Any help greatly appreciated!