Mathew K Analytics

Lesson 11 · Data Science Projects

Comprehensive Analysis and Visualization of Global Covid-19 Data Using Python

In this lesson, we will explore global Covid 19 data. You will learn how to analyze and visualize trends over time. Data mining can help you spot important…

⬇ Download notebookOpen in Colab ↗

What you'll learn

Data

No separate download needed — the notebook creates or downloads everything it uses.

📓 Full notebook

Download .ipynb

Global Covid 19 Data Analysis and Visualizations#

  • In this lesson, we will explore global Covid 19 data.
  • You will learn how to analyze and visualize trends over time.
  • Data mining can help you spot important patterns in real world health data.
  • Visualizations turn raw numbers into insights anyone can understand.
  • By the end, you will have skills to do your own data exploration projects.
  • This lesson is beginner friendly with clear, simple steps.

What is Covid 19 Data Mining?#

  • Data mining means finding patterns in large data collections.
  • Covid 19 datasets record infections, recoveries, and deaths worldwide.
  • With the right tools, you can visualize outbreaks, trends, and risks.
  • This helps scientists, leaders, and the public understand what is happening.
  • We use Python because it is powerful yet beginner friendly.
# Always suppress warnings for a smooth experience
import warnings; warnings.filterwarnings("ignore")
import numpy as np
np.random.seed(42)
# Data setup
import pandas as pd
url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv'
df = pd.read_csv(url)
print(df.shape)
print(df.head(3))
(289, 1147)
  Province/State Country/Region       Lat       Long  1/22/20  1/23/20  \
0            NaN    Afghanistan  33.93911  67.709953        0        0   
1            NaN        Albania  41.15330  20.168300        0        0   
2            NaN        Algeria  28.03390   1.659600        0        0   

   1/24/20  1/25/20  1/26/20  1/27/20  ...  2/28/23  3/1/23  3/2/23  3/3/23  \
0        0        0        0        0  ...   209322  209340  209358  209362   
1        0        0        0        0  ...   334391  334408  334408  334427   
2        0        0        0        0  ...   271441  271448  271463  271469   

   3/4/23  3/5/23  3/6/23  3/7/23  3/8/23  3/9/23  
0  209369  209390  209406  209436  209451  209451  
1  334427  334427  334427  334427  334443  334457  
2  271469  271477  271477  271490  271494  271496  

[3 rows x 1147 columns]

A Quick Look at the Data#

  • Each row is a country or region.
  • The first columns hold country and location details.
  • The remaining columns give confirmed case numbers for each day.
  • Our goal is to analyze how cases changed over time and across places.
# See basic info about the table and columns
df.info()
 
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 289 entries, 0 to 288
Columns: 1147 entries, Province/State to 3/9/23
dtypes: float64(2), int64(1143), object(2)
memory usage: 2.5+ MB
# Check for any missing values
print(df.isnull().sum().head())
Province/State    198
Country/Region      0
Lat                 2
Long                2
1/22/20             0
dtype: int64

Preparing Data for Analysis#

  • To visualize trends, we need totals per day for the world.
  • We will sum all countries for each date column.
  • This creates a global time series to plot.
# Get global daily total confirmed cases
date_cols = df.columns[4:]
global_total = df[date_cols].sum()
print(global_total.head())
1/22/20     557
1/23/20     657
1/24/20     944
1/25/20    1437
1/26/20    2120
dtype: int64
# Plot global cases over time
import matplotlib.pyplot as plt
 
plt.figure(figsize=(10,5))
plt.plot(global_total.index, global_total.values)
plt.title("Worldwide Covid 19 Confirmed Cases Over Time")
plt.xlabel("Date")
plt.ylabel("Total Cases")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
No description has been provided for this image
# Show first 10 days and last 10 days in the global total
print("First 10 days:")
print(global_total.head(10))
print("\nLast 10 days:")
print(global_total.tail(10))
First 10 days:
1/22/20     557
1/23/20     657
1/24/20     944
1/25/20    1437
1/26/20    2120
1/27/20    2929
1/28/20    5580
1/29/20    6169
1/30/20    8237
1/31/20    9927
dtype: int64

Last 10 days:
2/28/23    675322238
3/1/23     675542852
3/2/23     675731911
3/3/23     675914580
3/4/23     675968775
3/5/23     676024901
3/6/23     676082941
3/7/23     676213378
3/8/23     676392824
3/9/23     676570149
dtype: int64

Focusing on Individual Countries#

  • Sometimes we want to zoom in on a single country.
  • This helps compare trends between places like USA, India, or Italy.
  • We will show how to select a specific country and plot its trend.
# Pick a country to explore (for example, India)
india = df[df['Country/Region'] == 'India']
india_total = india[date_cols].sum()
 
plt.figure(figsize=(10,5))
plt.plot(india_total.index, india_total.values, color='orange')
plt.title("Covid 19 Confirmed Cases in India Over Time")
plt.xlabel("Date")
plt.ylabel("Total Cases")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
No description has been provided for this image
# Let the user choose a country to plot
country_name = input("Type a country name, for example 'Italy': ")
country_data = df[df['Country/Region'] == country_name]
country_total = country_data[date_cols].sum()
 
plt.figure(figsize=(10,5))
plt.plot(country_total.index, country_total.values, color='green')
plt.title(f"Covid 19 Confirmed Cases in {country_name} Over Time")
plt.xlabel("Date")
plt.ylabel("Total Cases")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
No description has been provided for this image
# Compare top 5 affected countries
top5 = df.groupby('Country/Region')[date_cols[-1]].sum().sort_values(ascending=False).head(5)
print("Top 5 countries by total confirmed cases:")
print(top5)
Top 5 countries by total confirmed cases:
Country/Region
US         103802702
India       44690738
France      39866718
Germany     38249060
Brazil      37076053
Name: 3/9/23, dtype: int64
# Bar chart of top 5 countries
import seaborn as sns
 
plt.figure(figsize=(8,6))
sns.barplot(x=top5.values, y=top5.index, palette='Reds_r')
plt.xlabel("Total Confirmed Cases")
plt.ylabel("Country")
plt.title("Top 5 Countries by Confirmed Covid 19 Cases")
plt.tight_layout()
plt.show()
No description has been provided for this image

Discovering New Daily Cases#

  • Total numbers are useful, but it helps to see day by day changes.
  • New daily cases show how fast an outbreak is growing or shrinking.
  • We can compute daily new cases by subtracting each day's total from the previous day's.
# Calculate new global cases per day
new_cases = global_total.diff().fillna(0).astype(int)
print(new_cases.head(10))
1/22/20       0
1/23/20     100
1/24/20     287
1/25/20     493
1/26/20     683
1/27/20     809
1/28/20    2651
1/29/20     589
1/30/20    2068
1/31/20    1690
dtype: int32
# Plot new global daily cases
plt.figure(figsize=(10,5))
plt.bar(new_cases.index, new_cases.values, color='blue')
plt.title("New Confirmed Covid 19 Cases Each Day (World)")
plt.xlabel("Date")
plt.ylabel("New Cases")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
No description has been provided for this image

Summary and Next Steps#

  • We loaded and inspected a real Covid 19 dataset.
  • We visualized global and country specific trends.
  • We saw how to compare nations and spot changes over time.
  • There is much more to explore data mining opens many doors.
  • Try changing the country, plotting different time windows, or exploring deaths and recoveries.
  • To keep learning, please subscribe and check out other lessons on this channel!
  • Practice makes perfect keep experimenting with your own questions.

Found this useful?

All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.