From GDP and stock market correlations… to recession tagging… to unemployment trends… to bonds vs stocks behavior…
Today officially wraps up my finance-focused Data Science practice, and what a journey it has been 🤍
In this final exercise, I analyzed the long-standing relationship between stock prices and bond prices using real market data.
After reshaping the bond data with .melt(), filtering only closing values with .query(), and merging it with Dow Jones stock returns using merge_ordered(), I visualized both series over time.
The plot clearly shows an inverse relationship:
When stocks rise, bonds tend to fall
When stocks fall, bonds tend to rise
This is exactly what happens in real financial markets. During periods of uncertainty (like the 2008 crisis), investors move money out of risky assets (stocks) into safer assets (government bonds). This causes stock prices to drop while bond prices rise.
Beyond just the plot, here is what I truly learned from this entire finance module:
How to reshape real economic data using melt()
How to align time-based data properly with merge_asof() and merge_ordered()
How to tag economic periods like recessions
How to visualize financial behavior across time
And most importantly, how to think like an analyst
Data doesn’t just tell stories, it confirms market behavior.
I am grateful for how far I have come so far.
Yes! I just completed the 'Joining Data with Pandas' module and I am excited to move into the next phase of my learning journey - Introduction to Statistics with Python🤸
Thank you Africa Agility Foundation
Thank you DataCamp
Thank you Senior Data Scientist, Aaren Stubberfield, MS, for creating this masterpiece!
If you have been following along, thank you. More growth ahead🥂
-SP
Top comments (0)