Why Housing Watchers Should Learn Python Programming
Welcome back to Home Economics, a newsletter about the American housing market. Below my brief comments, today’s guest post is by Martin Wong of Autonomous Econ. What tools do you use to analyze data? After being an Excel jockey for most of my career, I've switched over to using Python—a coding language—over the last year. Almost all of the analysis you see here at Home Economics is now powered by Python. I can't tell you how much learning to code (with a big helping hand from ChatGPT) has changed my view—about the kind of work I can do, and even about the future of work itself. Today guest post—by Martin Wong, the author of Autonomous Econ—should be helpful for anyone who, like me, wants to find insights from large data sets but comes from a non-technical background. I hope you find his gentle introduction to Python here helpful. Martin Wong: Why Python?I had zero interest in computer programming growing up and leaned more toward Economics and Political Science during my high school and university years. If you had told me at graduation that I would one day work as a Data Science Consultant in a tech firm and use Python programming daily, I would have been completely confused. But I’m glad that’s how my career turned out. Python is a free, open-source, general-purpose programming language designed with an emphasis on code readability. Its potential is immense for everyday data and business analysts—including those working in the housing market—not just computer scientists. Python is the language of AI and Machine Learning, and it has taken the top spot this year among programming languages. Source: GitHub—the leading public repository for open-source code. In my first job as a macroeconomic forecaster, I encountered numerous roadblocks with traditional paid software like EViews, MATLAB, and tools such as Excel. I couldn’t create a map chart or automate many of my data extraction and analysis tasks. Python can handle all of this and much more¹. You can use it to:
The great thing is, you can learn Python 10x faster today than I did five years ago, thanks to tools like Claude and ChatGPT. These AI assistants act as personalized coding tutors, providing templates for anything you want to accomplish. Having Python knowledge means gaining a future-proof skill that frees you from reliance on paid third-party tools for tasks like those mentioned above. Data visualization is a fantastic starting point for learning Python in an engaging way because it allows you to work with datasets that interest you. Along the way, you’ll learn many core concepts, including data wrangling, functions, conditional statements, and loops. In this post, I will demonstrate four ways to enhance your data visualizations using only Python. Small multiples Small multiples are an excellent way to manage the dreaded spaghetti plot—those plots where you have too many lines and can’t make out a clear trend. This plot is essentially a matrix of smaller, individual plots, making it easier to see the patterns across categories. Python makes creating these plots straightforward. You can design a single template plot and then map or loop your data over it to generate the same plot for different categories. Below is an example I created to visualize the net inflows and outflows of permanent and long-term migrants in New Zealand. Link to source code. Using small multiples, I can easily see trends for each citizenship and determine whether net inflows or outflows are driven more by departures or arrivals. This approach also makes it easier to compare absolute levels across citizenships, which would be more difficult with a visualization like a stacked area plot. The possibilities for chart design are endless, including customizations for colors, fonts, and styles. However, if you’re feeling lazy, there are also libraries that generate beautiful plots right out of the box². Maps Plotting data onto maps has always been challenging, but it is worth learning because maps are universally engaging. Fortunately, Python offers libraries that handle geospatial data easily, eliminating the need for expensive GIS software. For example, you can quickly build choropleth maps using libraries like Plotly. Here is a map I created to visualize home ownership data, which I extracted from FRED (using Python!) for all states. Link to source code. I had the flexibility to make simple enhancements that made the map more intuitive. For instance, I added annotations to display values directly on the map, so users don’t have to constantly jump back to the legend. Additionally, having a binned legend with an appropriate color palette conveys the message that low home ownership is subjectively bad (in red). If you’re interested, I wrote a deep dive on building geo maps with Python here. Animation plots Dynamic storytelling plots have become increasingly popular with the shift away from print media. There are excellent examples from @Alvin Chang at Big Charts. Python offers libraries that enable the creation of transitions and animations, either within a single plot or between multiple plots. You can even display text dynamically, helping to tell a story and highlight important events. I was able to create this basic animation plot in a couple of hours from the home ownership data. It could be polished further by using smoother animations for the lines and adding text annotations to tell a story. Link to source code. Animation plots are certainly novel, and Python allows you to make them without having to learn web development or Java. Interactive dashboards Interactive dashboards are another data visualization tool that you can build with Python without needing web development skills. They are best used as a data exploration tool rather than for publication, as they place the burden on the reader to extract insights. When you have a large and interesting dataset, it allows you and highly engaged users, such as business stakeholders or journalists, to dive deeper into the data. You can easily host the dashboard on the web and share the URL with anyone, like my dashboard on migration flows in New Zealand. Built with Streamlit: link to dashboard. How you can start your Python journey As you can see, Python is very versatile as a tool for data visualization. If you’re interested in starting your journey with Python, I would recommend this tutorial from Kaggle to learn the fundamentals interactively. Beyond that, I suggest using ChatGPT and a Google Colab notebook (for running code) to learn in a personalized way tailored to what you want to achieve. The Python Graph Gallery is a great resource if you need inspiration for data visualization projects. Of course, I also regularly share basic tutorials for charts (like the ones above) and other Python hacks for everyday data analysts on my Substack. Martin is a data science consultant. Over at Autonomous Econ, he helps analysts with little training in data science harness the power of Python in their work. 1 The exception is R but Python is generally better at connecting with a wide variety of tools and systems due to its extensive libraries for tasks like web scraping, automation, and API integration. 2 Both Seaborn and Plotly offer useful templates for creating polished designs right out of the box. Plotly also provides the added benefit of generating interactive plots by default Home Economics is a reader-supported publication. Please consider upgrading to a paid subscription to support our work. Paying clients receive access to the full archive, forecasts, data sets, and exclusive in-depth analysis. This edition is free—you can forward it to colleagues who appreciate concise, data-driven housing analysis. |
Older messages
Five Innovations that Could Upend the Housing Market
Wednesday, November 20, 2024
Don't overlook technology's role in shaping housing demand–and supply. Here are five technologies that will make a difference. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
Happy News
Tuesday, November 5, 2024
Paternity leave and guest authors ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
The Week in Review
Sunday, October 20, 2024
Week of Oct 7 — Buyers brighten, inflation eases ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
The Week in Review
Saturday, October 5, 2024
Week of Sept 30th — Payrolls pop ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
The Week in Review
Sunday, September 15, 2024
Week of Sept 9 — Housing sentiment sags, Prices plod ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
You Might Also Like
How to Browse the Dark Web 👀
Tuesday, December 3, 2024
How to Maximize Your Travel Loyalty Benefits Before the End of the Year. You can visit the dark web safely and legally, if you know how. Not displaying correctly? View this newsletter online.
Khloé Kardashian Sets Herself Free
Tuesday, December 3, 2024
Introducing Bustle's December cover star. Dec. 3, 2024 Bustle Daily Khloé Kardashian Sets Herself Free EXCLUSIVE Khloé Kardashian Sets Herself Free Being stopped in public is par for the course
The Things Your Wedding Guests Secretly Despise
Tuesday, December 3, 2024
Today in style, self, culture, and power. The Cut December 3, 2024 INTRODUCING OUR NEW APP The New York App for iPhone is here. Download our free iOS app for the most enjoyable way to read the
Camila Cabello Unleashes Her Freak
Tuesday, December 3, 2024
Plus: The best TV shows of 2024, according to W editors. • Dec. 3, 2024 Up Next Your complete guide to industry-shaping entertainment news, exclusive interviews with A-list celebs, and what you should
Guys at the Grocery Store
Tuesday, December 3, 2024
Just a reminder that I have a sale going on everything in my Etsy shop, 15% off from now until December 15! ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
2024 Fashion Gift Guide
Tuesday, December 3, 2024
A trio of picks for the style lover or clothes horse in your life. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
Simon Says
Tuesday, December 3, 2024
Thoughts and observations on the evolution of outlet shopping ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏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