Hi Reader,
Last week, I released a 3-hour video, My top 50 scikit-learn tips.
I also finished Chapter 10 of my next ML course, which I'll tell you about once all 20 chapters are done 😅
Anyway, let’s get to today’s tip!
For fun, I’ve been building an interactive dashboard using pandas, Plotly Express, and Shiny for Python. (Check out a screenshot here.)
The goal is to help me analyze sales of my online courses. And since I’m working with sales data, I’m reminded of how much I love the pandas resample function!
Let’s see an example of how to resample 😉
Pretend you have a DataFrame of sales data that looks like this:
You might ask: What are my total sales for each product?
In that case, you would use groupby:
You can read that code as: For each Product, this is the sum of the Sale column.
Another similar question you might ask is: What are my total sales for each day?
Instead of groupby, you would use resample, which I think of as “groupby for time series data”:
You can read that code as: For each day, this is the sum of the Sale column.
(Notice that it inserted 2023-03-31 with a value of 0, since there were no sales on that day.)
By changing the 'D' to an 'M', you can resample by month instead:
'D' and 'M' are known as the “offset alias”, and there are many other offset aliases you can use.
Finally, let’s say that the index is not a datetime column:
In that case, you need to use the 'on' parameter to specify the datetime column:
If you work with time series data, I bet you’ll find a use for resample!
If you enjoyed this week’s tip, please forward it to a friend! Takes only a few seconds, and it really helps me out! 🙌
See you next Tuesday!
- Kevin
P.S. What’s the worst volume control interface? (my favorite is #12)
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, I'm thrilled to announce that my new book, Master Machine Learning with scikit-learn, is now on sale! Buy from Amazon I poured my heart and soul into making this the highest quality and most practical Machine Learning book available. Publishing this book is a dream come true, and I'd be grateful if you'd consider picking up a copy! 🙏 Option 1: Get the paperback from Amazon ($19) Although most technical books of this size (300+ pages) tend to sell for at least $39, I've priced the...
Hi Reader, A few months ago, I announced that my new book, Master Machine Learning with scikit-learn, would be published in December. Since then, my personal life has undergone some dramatic changes 🥴 During the transition, it has been challenging to focus on anything other than bare life essentials 🍽️ 🛌 🚿 Thankfully, my life has begun to steady (yay!), and so in the past few weeks I've been able to wrap up some key pieces of the project! ✅ I'm thrilled to hold in my hands the FINAL proof...
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...