Created
July 27, 2020 06:34
-
-
Save naenumtou/3deda352cefeed75441b61225d304bd7 to your computer and use it in GitHub Desktop.
This file contains 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
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