Visualizing COVID-19 Cases and Deaths in December using Python
Table of Contents
- Introduction
- Full Code
- Step-by-Step Explanation
- Math Behind Trends
- Sample Output
- Insights
- Related Articles
Introduction
COVID-19 datasets contain daily records of cases and deaths. By visualizing this data, we can easily identify trends, spikes, and patterns.
Full Python Code
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("https://www.sololearn.com/uploads/ca-covid.csv")
df.drop('state', axis=1, inplace=True)
df['date'] = pd.to_datetime(df['date'], format="%d.%m.%y")
df['month'] = df['date'].dt.month
df.set_index('date', inplace=True)
(df[df['month']==12])[['cases','deaths']].plot()
plt.savefig('plot.png')
plt.show()
Step-by-Step Explanation
1. Reading Data
We load CSV data into a DataFrame using Pandas.
2. Data Cleaning
We remove unnecessary columns like state to simplify analysis.
3. Date Conversion
Dates are converted into proper datetime format for filtering and plotting.
4. Filtering December
We extract only rows where month = 12.
Math Behind the Trend (Simple)
Growth Rate
Growth Rate = (New Cases - Old Cases) / Old Cases
๐ Helps measure how fast cases are increasing.
Slope (Trend Line)
Slope = ฮY / ฮX
๐ Shows whether cases are rising or falling.
Sample Output (CLI Style)
date cases deaths
2020-12-01 15000 200
2020-12-02 16000 210
2020-12-03 17000 230
Insights from the Graph
- Identify peaks in cases
- Compare deaths vs cases
- Observe trends (rise/fall)
Related Articles
Conclusion
By combining Pandas and Matplotlib, we can easily analyze and visualize real-world datasets. Understanding trends is critical for decision-making.