Skip to content

Instantly share code, notes, and snippets.

@naenumtou
Created July 27, 2020 06:34
Show Gist options
  • Save naenumtou/3deda352cefeed75441b61225d304bd7 to your computer and use it in GitHub Desktop.
Save naenumtou/3deda352cefeed75441b61225d304bd7 to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
import requests
#Request API
url = 'https://corona.lmao.ninja/historical'
r = requests.get(url)
j = r.json()
#Create dataframe
f = pd.DataFrame(j)
ct = f['country'].tolist()
df = pd.json_normalize(f['timeline'])
df['country'] = ct
df = pd.DataFrame(df.set_index(['country']).stack(), columns = ['total'])
df = df.reset_index()
c = df['level_1'].str.split('.', n = 1, expand = True)
df = df.drop(['level_1'], axis = 1)
df['types'] = c[0]
df['date'] = c[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment