Python to check data about coronavirus in Italy

I made a new version of the code about looking for data about coronavirus in Italy. I made a more clear view of the data and referring just to yesterday (the latest data). It will check yesterdays date by itself with datetime.

Check this in a jupyter notebook

import pandas as pd
from datetime import datetime


yesterday = str(datetime.today().day-1)
month = str(datetime.today().month)
print(f"{yesterday}/{month}")

def check(what, day):
	url = f"https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-{what}.csv"

	df = pd.read_csv(url, error_bad_lines=False)
	print(what, end=" ")
	result = df.loc[df["Country/Region"]=="Italy"][f"{month}/{day}/20"]
	print(list(result))

what = "Confirmed", "Recovered", "Deaths" 
for w in what:
	check(w, yesterday)

This is the output

25/2
Confirmed [322]
Recovered [1]
Deaths [10]
>>>

Whatching data of the last 3 days

import pandas as pd
from datetime import datetime

days = []
for n in range(5, 0, -1):
    days.append(str(datetime.today().day-n))

month = str(datetime.today().month)

def check(what, day):
    url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-{}.csv".format(what)

    df = pd.read_csv(url, error_bad_lines=False)
    print(what, end=" ")
    result = df.loc[df["Country/Region"]=="Italy"]["{}/{}/20".format(month, day)]
    print(list(result), end=" - ")


what = "Confirmed", "Recovered", "Deaths" 

for d in days:
    print("{}/{}".format(d, month), end=": ")
    for w in what:
        check(w, d)
    print()

output

21/2: Confirmed [20] - Recovered [0] - Deaths [1] - 
22/2: Confirmed [62] - Recovered [1] - Deaths [2] - 
23/2: Confirmed [155] - Recovered [2] - Deaths [3] - 
24/2: Confirmed [229] - Recovered [1] - Deaths [7] - 
25/2: Confirmed [322] - Recovered [1] - Deaths [10] -

Try the code in this interactive shell

Run the following code in this page

Python data about Coronavirus

import pandas as pd from datetime import datetime days = [] for n in range(5, 0, -1): days.append(str(datetime.today().day-n)) month = str(datetime.today().month) def check(what, day): url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-{}.csv".format(what) df = pd.read_csv(url, error_bad_lines=False) print(what, end=" ") result = df.loc[df["Country/Region"]=="Italy"]["{}/{}/20".format(month, day)] print(list(result), end=" - ") what = "Confirmed", "Recovered", "Deaths" for d in days: print("{}/{}".format(d, month), end=": ") for w in what: check(w, d) print()
Just press 'Run'.

Shell with graph of confirmed cases

Python data about Coronavirus

import pandas as pd from datetime import datetime import matplotlib.pyplot as plt days = [] for n in range(5, 0, -1): days.append(str(datetime.today().day-n)) month = str(datetime.today().month) c = [] def check(what, day): url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-{}.csv".format(what) df = pd.read_csv(url, error_bad_lines=False) print(what, end=" ") result = df.loc[df["Country/Region"]=="Italy"]["{}/{}/20".format(month, day)] print(list(result)[0], end=" - ") if what == "Confirmed": c.append(list(result)[0]) what = "Confirmed", "Recovered", "Deaths" for d in days: print("{}/{}".format(d, month), end=": ") for w in what: check(w, d) print() ind = range(len(c)) p = plt.bar(ind, c) plt.xlabel("giorni") plt.ylabel("Casi confermati") plt.show()
Just press 'Run'.


Subscribe to the newsletter for updates
Tkinter templates
My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts