Example usage

To use covizpy in a project, import the package with following commands:

Imports

from covizpy.get_data import get_data
from covizpy.plot_summary import plot_summary
from covizpy.plot_spec import plot_spec
from covizpy.plot_metric import plot_metric

import altair as alt
alt.renderers.enable('html')
from altair import limit_rows, to_values
from toolz.curried import pipe
t = lambda data: pipe(data, limit_rows(max_rows=1000000), to_values)
alt.data_transformers.register('custom', t)
alt.data_transformers.enable('custom')
DataTransformerRegistry.enable('custom')

To use the functions, see below examples:

Retrieve COVID-19 data

We will first create a dataframe to retrieve COVID-19 data using get_data() function with a specified date range and default all locations.
Note that the number of columns displayed here are truncated to fit the page.

df = get_data(date_from="2022-01-01", date_to="2022-01-21")
df.head().iloc[:,:6]
iso_code continent location date total_cases new_cases
677 AFG Asia Afghanistan 2022-01-01 158107.0 23.0
678 AFG Asia Afghanistan 2022-01-02 158189.0 82.0
679 AFG Asia Afghanistan 2022-01-03 158183.0 -6.0
680 AFG Asia Afghanistan 2022-01-04 158205.0 22.0
681 AFG Asia Afghanistan 2022-01-05 158245.0 40.0

Plot summary graph (bar chart)

We now create a summary bar graph using plot_summary() to visualize COVID-19 cases in different countries inside the specified time period.

plot_summary(df, var="location", val="new_cases", fun="sum", date_from="2022-01-01", date_to="2022-01-15", top_n=10)

Plot COVID-19 cases for specific countries (line chart)

After seeing the summary of COVID-19 cases in several countries, we pass in a list of countries we plot the trend of new cases in the time period using plot_spec() function.

plot_spec(df, location=["Canada", "Turkey"], val="new_cases", date_from="2022-01-01", date_to="2022-01-07")

Plot new COVID-19 cases versus another metric (line chart)

Now we illustrate the trend of new cases for a specific location with another suitable metric using plot_metric() function.

plot_metric(location = "Canada", metric="positive_rate", date_from="2022-01-01", date_to="2022-01-15")