Ohanian / Oct 05 2020
Remix of World COVID-19 numbers by OOhanian
div.ProseMirror
Obtain UK numbers

Remix this to get started with Julia "Julia version 1.4.1".
"Julia version $VERSION"0.5s
Julia
"Julia version 1.4.1"
using CSV,DataFrames,Dates,HTTP0.5s
Julia
import Pkg;Pkg.add("Query");using Query22.0s
Julia
function CSV_read_website(url::String,args...;kwargs...) response = HTTP.get(url) response_body = String(response.body) io_buff=IOBuffer(response_body) return CSV.read(io_buff,args...;kwargs...)end0.2s
Julia
CSV_read_website (generic function with 1 method)
data = CSV_read_website("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")0.6s
Julia
# Rename the first column of data to "state"# Rename the second column of data to "country"rename!(data,1 => "state",2 => "country")# If the value in the state column is empty then set it to the string "empty"data.state = coalesce.(data.state, "empty")0.2s
Julia
266-element Array{String,1}:
"empty"
"empty"
"empty"
"empty"
"empty"
"empty"
"empty"
"empty"
"Australian Capital Territory"
"New South Wales"
⋮
"empty"
"empty"
"empty"
"empty"
"empty"
"empty"
"empty"
"empty"
"empty"
Now we create a function to obtain the daily new cases for a particular country
function obtain_dailycases(country::String) Nation_row = data |> ( _.state == "empty" && _.country == country ) |> DataFrame Nation_cases = collect(Nation_row[1, 5:end]) Nation_newcases = Float64.(similar(Nation_cases)) Nation_newcases[1] = 0.0 for k = 2:length(Nation_cases) Nation_newcases[k] = Nation_cases[k] - Nation_cases[k-1] end date_strings = String.(names(data))[5:end] format = Dates.DateFormat("m/d/Y") Nation_dates = parse.(Date, date_strings, format) .+ Dates.Year(2000) return (Nation_dates, Nation_newcases)end0.2s
Julia
obtain_dailycases (generic function with 1 method)
# Look for the whole Country only data# This is where the first column has the value "empty"mylist = findall( x -> x=="empty", data[:,1])# Look for countried with the word "United" in itfor n in mylist if occursin("United", data[n, 2]) println(data[n, 2]) endendprintln()0.6s
Julia
Now we can extract the data for the country "United Kingdom"
# Get the array of dates and the array of Daily Cases(UK_dates,UK_cases) = obtain_dailycases("United Kingdom")0.5s
Julia
(Date[2020-01-22, 2020-01-23, 2020-01-24, 2020-01-25, 2020-01-26, 2020-01-27, 2020-01-28, 2020-01-29, 2020-01-30, 2020-01-31 … 2020-09-25, 2020-09-26, 2020-09-27, 2020-09-28, 2020-09-29, 2020-09-30, 2020-10-01, 2020-10-02, 2020-10-03, 2020-10-04], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0 … 6873.0, 6041.0, 5692.0, 4044.0, 7143.0, 7108.0, 6914.0, 6968.0, 12871.0, 22961.0])
# Find the start date of 1st August 2020startloc = first( findall(x->x==Date(2020,8,1),UK_dates) )result_dates = UK_dates[startloc:end]result_cases = UK_cases[startloc:end]for n = 1:length(result_dates) value_integer = Int64(floor(result_cases[n])) println(result_dates[n],",",value_integer)end0.7s
Julia