Day 39 of 100 Days Coding Challenges: Python
Ah, 2020. The year when “going viral” took on a whole new (and not-so-fun) meaning. I remember first hearing about COVID-19 on the news—some distant reports from China that felt like a world away. A blink later, and boom: the whole globe was upside down, hand sanitizer became currency, and toilet paper was basically gold.
Fast forward to today, and here I am, playing with data from that very same pandemic—except now, instead of panic-buying canned beans, I’m pulling country-specific COVID data from the internet and turning it into lovely little graphs using matplotlib to create my own COVID data visualization program. Over the past few days, I’ve been on a visual journey with this powerful library, and let me tell you: nothing makes data feel more satisfying than watching it turn into a line chart especially when that line isn’t going straight up.
The data source of the day is disease.sh, a surprisingly friendly API for something that deals with viruses. My plan? Fetch real-time data, choose a country, and see what the case numbers look like. And who knows? Maybe one day, this skill will sneak its way into my work life when nobody’s looking.
Today’s Motivation / Challenge
Today’s project is about turning chaos into clarity—something all programmers secretly dream of. There’s something almost poetic about visualizing a pandemic: it’s the difference between abstract panic and concrete trends. This project connects data science to real life, while giving your Python skills some real-world relevance. Bonus points if you feel like a data sorcerer by the end.
Purpose of the Code (Object)
This little script fetches historical COVID-19 case data for any country you choose and plots a neat line graph of daily new cases. It’s like Google Trends, but you made it yourself—with actual code and zero ads. The result? A quick, clear visual of what’s going on behind the numbers.
AI Prompt:
“Create a simple Python program that fetches COVID-19 case data from disease.sh and visualizes daily new cases using matplotlib.”
Functions & Features
- Fetches COVID-19 historical case data for the last 30 days
- Converts cumulative case data into daily new case counts
- Plots the results using a simple, clean line chart
Requirements / Setup
pip install requests matplotlib
Minimal Code Sample
response = requests.get(“https://disease.sh/v3/covid-19/historical/USA?lastdays=30”)
data = response.json()
cases = list(data[‘timeline’][‘cases’].values())
new_cases = [cases[i] – cases[i-1] for i in range(1, len(cases))]
plt.plot(new_cases)
plt.show()
This snippet fetches the last 30 days of COVID cases for the U.S. and plots daily new cases.
Notes / Lessons Learned
So, here’s the thing—I’ve been dancing with matplotlib for a couple of days now, and while I’m getting the hang of it, I still feel like it’s a slow waltz with occasional toe-stomping. The library itself is amazing if you’re pulling data off the internet, but setting up the project environment still feels like building IKEA furniture without the instructions.
I made the rookie mistake of renaming my project folder halfway through and then spent way too long trying to activate the wrong virtual environment. Hint: Python doesn’t respond to psychic guesses—you’ve gotta get the name right. Lesson learned. Anyhow, I managed to create a COVID data visualization in a Python program.
The structure of the plotting code feels eerily familiar now—almost like déjà vu with braces and colons. Maybe that’s a good sign: I’m starting to notice patterns, which means I’m leveling up.
Also, when I ran the U.S. data? There wasn’t much new info (thankfully), but the graph still did its thing like a loyal little data dog. Even in a post-peak-pandemic world, the code works, and that’s a small but nerdy joy.
Optional Ideas for Expansion
- Add an input field to let users type any country name
- Include a bar chart version for comparison
- Export the graph as an image to share with friends who still think Python is a snake
