pip install plotly
"./DataPreprocess"
display(df_cleaned_time_series.select($"reproduction_rate", $"location", $"date").filter($"reproduction_rate".isNotNull).filter(
$"location"==="Sweden" ||
$"location"==="Germany" ||
$"location"==="Danmark" ||
$"location"==="Finland" ||
$"location"==="Norway").sort("date"))
df_cleaned_time_series.createOrReplaceTempView("visual_rdd")
import pandas as pd
import numpy as np
import plotly.express as px
test_table = spark.table("visual_rdd")
country = np.array(test_table.select("iso_code").rdd.map(lambda l: l[0]).collect())
dates = np.array(test_table.select("date").rdd.map(lambda l: l[0]).collect())
total_cases = np.array(test_table.select("total_cases").rdd.map(lambda l: l[0]).collect())
total_deaths = np.array(test_table.select("total_deaths").rdd.map(lambda l: l[0]).collect())
new_cases = np.array(test_table.select("new_cases").rdd.map(lambda l: l[0]).collect())
new_deaths = np.array(test_table.select("new_deaths").rdd.map(lambda l: l[0]).collect())
visual_data = {'country':country.tolist(), 'total_cases':total_cases, 'date':dates,
'total_deaths': total_deaths, 'new_cases': new_cases, 'new_deaths': new_deaths}
visual_df = pd.DataFrame(data = visual_data).sort_values(by='date')
visual_df
Total Cases
fig = px.choropleth(visual_df[~visual_df.country.str.contains("WLD", na=False)], locations="country",
color="total_cases", # total_cases is a column of gapminder
hover_name="country", # column to add to hover information
color_continuous_scale=px.colors.sequential.Plasma,
animation_frame = 'date')
fig.show()
fig = px.choropleth(visual_df[~visual_df.country.str.contains("WLD", na=False)], locations="country",
color="total_deaths", # total_deaths is a column of gapminder
hover_name="country", # column to add to hover information
color_continuous_scale=px.colors.sequential.Plasma,
animation_frame = 'date')
fig.show()
fig = px.choropleth(visual_df[~visual_df.country.str.contains("WLD", na=False)], locations="country",
color="new_cases", # new_cases is a column of gapminder
hover_name="country", # column to add to hover information
color_continuous_scale=px.colors.sequential.Plasma,
animation_frame = 'date')
fig.show()
fig = px.choropleth(visual_df[~visual_df.country.str.contains("WLD", na=False)], locations="country",
color="new_deaths", # new_deaths is a column of gapminder
hover_name="country", # column to add to hover information
color_continuous_scale=px.colors.sequential.Plasma,
animation_frame = 'date')
fig.show()