This week’s topic: Egg prices
The covid-19 pandemic has caused all sorts of economic chaos over the last few years. Supply chains have been upended, millions of people have switched (or lost) their jobs, and inflation has been a topic of conversation for the first time in decades. And yes, central banks around the world have been raising rates, and yes, inflation seems to be slowing down. But prices are still higher than they were a few years ago.
One product whose prices have skyrocketed over the last few years are eggs. I don’t know about you; I tend not to think much about the price of eggs when I do my family’s shopping. (And yes, I’ve done the supermarket shopping for a very long time.) But for many people, the rise in egg prices has been pretty dramatic. And if you’re a business that depends on egg prices? Then it has started to affect your bottom line.
Here’s a story from the San Francisco Standard (a publication I know nothing else about, but whose article seems to explain things pretty well): https://sfstandard.com/arts-culture/food/san-francisco-donut-shop-reveals-insane-new-price-of-eggs/
This week, we’re going to look at egg data from the US Department of Agriculture (USDA). Here are the questions I’d like you to answer:
- Given URLs for each of the last five years of egg prices, create a single data frame.
- What was the average low price for eggs in each of the years of data?
- In what year was the percentage increase the greatest?
- Now get the average low price for eggs in each month and year of data.
- Have egg prices gone down in the last few months?
I’ll warn you right now that getting the data into a single data frame will be a bit tricky. That’s because you can only download up to two years of data at a time. The URL to download the data is:
f'https://marketnews.usda.gov/mnp/py-report?&repDate=01%2F01%2F{year}®ionsDesc=&endDate=12%2F31%2F{year}&repMonth=1&run=Run&_producttypefrom=1&endYear=2023&producttypefrom=&repYear=2020&categoryDesc=Egg&frequency=Daily&datatype=None+Selected&previouscls=Breaking+Stock&_producttype=1&report=NW_PY041&category=Egg&subcategory=Breaking+Stock&endMonth=1&commodityDesc=Breaking+Stock&runReport=true&format=excel' Notice that I’ve given you the URL as a Python f-string, with the expectation that the variable “year” will contain the year for which you want data.
Also: Even though the end of the URL says “format=excel”, and I got that URL from clicking on the “download Excel file” icon on the USDA site, it’s … not Excel. It’s actually a bunch of HTML tables. Weird? Yes! But welcome to the wild and wacky world of data, and working with it.
If you want to explore the USDA’s egg-price site, it’s here: https://marketnews.usda.gov/mnp/py-report-config?rowDisplayMax=500&repDate=01%2F01%2F2018®ionsDesc=&endDate=12%2F31%2F2018&repMonth=1&run=Run&_producttypefrom=1&endYear=2023&producttypefrom=&repYear=2020&categoryDesc=Egg&frequency=Daily&startIndex=1&datatype=None+Selected&previouscls=Breaking+Stock&_producttype=1&report=NW_PY041&category=Egg&subcategory=Breaking+Stock&endMonth=1&commodityDesc=Breaking+Stock&reportConfig=true&x=14&y=1
The learning goals for this week’s exercise are to turn multiple source files into a single data frame, to work with date-time information, to do some grouping, and to look at changes in the data.
Too easy? Too hard? Too few hints? Let me know! I’m still trying to figure out the appropriate type(s) of questions to ask in this newsletter, and any/all feedback is welcome.
I’ll be back tomorrow (on Thursday) with my answers to these questions.
Reuven