Skip to content

Instantly share code, notes, and snippets.

Avatar

vnegi10

  • Joined Jul 25, 2020
View GitHub Profile
View Top_five_recovered.jl
sort!(data_df_recovered,Symbol("7/31/20"),rev=true) # sort original DataFrame in descending order based on values in last column (latest date)
countries_sort_r = data_df_recovered[1:5,Symbol("Country/Region")] # list of top 5 countries
latest_recovered_cases = data_df_recovered[1:5,Symbol("7/31/20")] # number of recovered cases in top 5 countries
gr(size=(700,400))
display(bar(countries_sort_r, latest_recovered_cases,
orientation = :h,
xlabel = "Total number of recovered cases",
ylabel = "Countries",
legend = false,
View Make_a_bar_plot.jl
gr(size=(800,500))
display(groupedbar(names(y), Y,
bar_position = :dodge,
bar_width=0.75,
ylabel = "Number of cases",
xlabel = "Countries",
label=["Deaths" "Confirmed" "Recovered" "Currently infected"],
framestyle = :semi,
formatter = :plain,
legend = :topleft,
View Group_data_for_bar_plot.jl
confirmed_cases = vec(convert(Array, last(y,1))) # convert last dataframe row into a 1-D array
recovered_cases = vec(convert(Array, last(y_r,1)))
deaths = vec(convert(Array, last(y_d,1)))
Y = Array{Float64,2}(undef, length(names(y_r)), 4) # 2-D array with number of confirmed, recovered and deaths
Y[:,1] = deaths
Y[:,2] = confirmed_cases
Y[:,3] = recovered_cases
Y[:,4] = Y[:,2] - (Y[:,3] + Y[:,1]) # number of currently infected = confirmed - (recovered + deaths)
View Collect_more_data_for_countries.jl
countries = ["France", "Russia", "Italy", "Iran", "India", "Germany", "Brazil"];
y, y_r, y_d = DataFrame(), DataFrame(), DataFrame() # separate empty dataframes to keep things simple
################## For total confirmed cases #####################
for country in countries
data_dfr = find_country(data_df,country); # returns a dataframe row
data_dfr = DataFrame(data_dfr); # convert dataframe row back to a dataframe
rows, cols = size(data_dfr);
data_dfl = stack(data_dfr, 5:cols); # convert dataframe into long format
y[!,Symbol("$country")] = data_dfl[!,:value]
View Import_more_data.jl
file = download("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv", "covid_19_global_data_recovered.csv" ); # source of the data
data_df_recovered = DataFrame!(CSV.File("covid_19_global_data_recovered.csv")); # read data from file into a DataFrame
file = download("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv", "covid_19_global_data_deaths.csv" ); # source of the data
data_df_deaths = DataFrame!(CSV.File("covid_19_global_data_deaths.csv")); # read data from file into a DataFrame
View Julia_load_toml.jl
# Download .toml files from GitHub respository, activate the environment
using InstantiateFromURL
github_project("vnegi10/covid19-notebooks-julia", path="", version = "master", force = true)
View COVID_19_data_analysis_using_df.jl
# Load and compile Julia packages for the current session
# This might take a while, needs to be done only once
# Recommended to list and compile all packages at once
using Distributions
using StatsBase
using CSV
using DataFrames
using StatsPlots
using Plots
View Top_five.jl
sort!(data_df,Symbol("7/24/20"),rev=true) # sort original DataFrame in descending order based on values in last column (latest date)
countries_sort = data_df[1:5,Symbol("Country/Region")] # list of top 5 countries
latest_reported_cases = data_df[1:5,Symbol("7/24/20")] # number of reported cases in top 5 countries
gr(size=(700,400))
display(bar(countries_sort, latest_reported_cases,
orientation = :h,
xlabel = "Total number of confirmed cases",
ylabel = "Countries",
legend = false,
View Daily_reported_cases.jl
############################# Calculate number of daily reported cases ####################################
y_tmp = deepcopy(y); # creates an independent copy, changes in y_tmp won't affect y
rows,cols = size(y_tmp)
dfrows = nrow(y_tmp);
name = names(y_tmp);
y_daily = similar(y_tmp,dfrows-1); # copy the structure to an empty dataframe with dfrows-1 rows
View Plot_countries_time_series.jl
rows,cols = size(y)
gr(size=(900,600))
@df y plot(x, cols(1:cols),
label = reshape(names(y),(1,length(names(y)))),
xlabel = "Time",
ylabel = "Total number of reported cases",
xticks = x[1:7:end],
xrotation = 45,
marker = (:diamond,4),
You can’t perform that action at this time.