Covid-19 Data Analysis & Visualization
Build a small Covid-19 analysis project:
- Load time series case data
- Clean/parse dates
- Plot trends and moving averages
- Compare regions
Analysis pipeline
Section titled “Analysis pipeline”flowchart LR A["Raw time series
(daily cases)"] --> B["Clean
(parse dates, filter country)"] B --> C["Smooth
(7-day rolling average)"] C --> D["Visualize
(trend, region comparison)"] D --> E["Conclude
(peaks, seasonality)"]
Data sources
Section titled “Data sources”Possible sources:
- Our World in Data (OWID)
- Johns Hopkins dataset
Step 1: Load and inspect
Section titled “Step 1: Load and inspect”import pandas as pd
df = pd.read_csv("data/covid.csv")
print(df.shape)
print(df.head())Step 2: Parse dates and subset
Section titled “Step 2: Parse dates and subset”import pandas as pd
if "date" in df.columns:
df["date"] = pd.to_datetime(df["date"], errors="coerce")Step 3: Trend plot
Section titled “Step 3: Trend plot”import matplotlib.pyplot as plt
country = "India"
sub = df[df["location"] == country].sort_values("date")
plt.figure(figsize=(10, 4))
plt.plot(sub["date"], sub["new_cases"], label="new_cases")
plt.title(f"New cases over time - {country}")
plt.xlabel("Date")
plt.ylabel("New cases")
plt.xticks(rotation=20)
plt.tight_layout()
plt.show()Step 4: Moving average
Section titled “Step 4: Moving average”sub = sub.copy()
sub["new_cases_ma7"] = sub["new_cases"].rolling(7).mean()
plt.figure(figsize=(10, 4))
plt.plot(sub["date"], sub["new_cases"], alpha=0.4, label="daily")
plt.plot(sub["date"], sub["new_cases_ma7"], label="7-day avg")
plt.title(f"New cases (7-day avg) - {country}")
plt.legend()
plt.tight_layout()
plt.show()Step 5: Compare regions
Section titled “Step 5: Compare regions”import seaborn as sns
import matplotlib.pyplot as plt
countries = ["India", "United States", "Brazil"]
sub = df[df["location"].isin(countries)].copy()
sub = sub.sort_values("date")
plt.figure(figsize=(10, 4))
sns.lineplot(data=sub, x="date", y="new_cases", hue="location")
plt.title("New cases comparison")
plt.xticks(rotation=20)
plt.tight_layout()
plt.show()Visualize it
Section titled “Visualize it”Deliverable
Section titled “Deliverable”Write a short report:
- When did peaks occur?
- Is the trend seasonal?
- What data quality issues exist (missing dates/values)?
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Parse dates
Section titled “Exercise 1 – Parse dates”Exercise 2 – 7-day rolling average
Section titled “Exercise 2 – 7-day rolling average”Exercise 3 – Filter one country’s data
Section titled “Exercise 3 – Filter one country’s data”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading