Hi Reader,
In two weeks, Iāll be offering a Black Friday sale on ALL of my courses.
Iāll send you the details next week!
āEasier data analysis with pandas (free)
This is my video series about pandas, the most popular Python library for data analysis. There are 30+ videos, most of which are designed for pandas beginners, though intermediate users can skip to the ābonusā videos at the bottom.
Normally I wonāt link to my own tutorials in this section, but it seemed appropriate since the next few tips will be about pandas! š¼
In last weekās tip, I showed you three visualizations that I created from the World Happiness Report data: a world map, a line chart, and an arrow chart.
I created those visualizations using Datawrapper, a no-code tool that I highly recommend checking out!
As is the case with many Data Science projects, I spent most of my time on the data cleaning step. Once the data was clean, Datawrapper made the visualization step quite easy!
In this weekās tip, Iām going to show you how I transformed the raw data into the world map data using pandas. Here are the specific steps Iāll demonstrate:
If you want to follow along with the code, you can run it online using Google Colab.
Hereās the end result:
The dataset is stored online in an Excel sheet, so I read it directly from the URL using the read_excel function. (Note that I split the URL string into two lines by adding parentheses around it.)
To avoid storing unnecessary data, I only kept the three columns that were relevant for the analysis. Life Ladder is the average ālife evaluationā reported by residents, on a scale from 0 to 10, and is the reportās primary measure of happiness.
I renamed the columns so that they are lowercase, have no spaces, and are more descriptive. Not only does this create consistency, but it also allows me to use dot notation instead of bracket notation for column selection.
I also rounded the happiness column to 2 digits using the round method (since thatās enough precision for the purpose of this visualization), and I overwrote the existing happiness column with an assignment statement.
First, I used the unique method to display all of the country names in the dataset.
However, not all of the country names used by the World Happiness Report (WHR) are the same as the ones used by Datawrapper. For example, the WHR uses Congo (Brazzaville) and Congo (Kinshasa), whereas Datawrapper uses Congo and Democratic Republic of Congo.
Second, I created a dictionary to map the WHR names to the Datawrapper names.
Finally, I used the replace method to update the country names, overwrote the existing column, and used the unique method to check that the operation worked.
I filtered the DataFrame using a condition so that only the rows from 2022 remained.
I wrote the contents of the DataFrame to a file using the to_csv method, and excluded the index from the CSV since itās not meaningful.
Once I uploaded the CSV into Datawrapper, it was easy to customize the mapās appearance and publish it online.
Again, hereās the end result, which you can click on and interact with:
If you enjoyed this weekās tip, please forward it to a friend! Takes only a few seconds, and it really helps me reach more people! š
See you next Tuesday!
- Kevin
P.S. Ace your next job interview with zero knowledgeā
Did someone awesome forward you this email? Sign up here to receive Data Science tips every week!
Join 25,000+ intelligent readers and receive AI tips every Tuesday!
Hi Reader, happy new year! š I wanted to share with you the three most important articles I found that look back at AI progress in 2025 and look forward at what is coming in 2026 and beyond. Iāve extracted the key points from each article, but if you have the time and interest, Iād encourage you to read the full articles! š The Shape of AI: Jaggedness, Bottlenecks and Salients By Ethan Mollick āJaggednessā describes the uneven abilities of AI: Itās superhuman in some areas and far below human...
Hi Reader, I just published a new YouTube video: How to use top AI models on a budget Description: Want to chat with the best AI models from OpenAI, Claude, and Google without paying $20/month? I'll show you how to use API keys with TypingMind to access top models for a fraction of the cost, demonstrate its killer feature of chatting with multiple models side-by-side, and explain when paying for a subscription is actually the smarter choice. Timestamps: 0:00 Introduction 0:37 Pay-per-token...
Hi Reader, On Friday, I announced my forthcoming book, Master Machine Learning with scikit-learn. In response, my Dad asked me: How does the subject of this book relate to Artificial Intelligence? In other words: What's the difference between AI and Machine Learning? Ponder that question for a minute, then keep reading to find out how I answered my Dad... š AI vs Machine Learning Here's what I told my Dad: You can think of AI as a field dedicated to creating intelligent systems, and Machine...