Tuesday Tip #5: Visualize your pandas code 🐼


Hi Reader!

Today’s tip is most useful if you already have some experience with pandas, which is the main data analysis library in Python.

If you’re brand new to pandas, I recommend starting here:

🔗 Easier data analysis with pandas (my free video series)

Let’s move on to today's tip!


👉 Tip #5: Visualize your code with Pandas Tutor

In order to progress from pandas beginner to intermediate (and beyond), it’s important to build a mental model of what happens when you run your pandas code.

If you’re struggling to build that mental model, Pandas Tutor might be the perfect tool for you!

For example, if you input code like this:

dogs.groupby('size').mean()

Pandas Tutor outputs a diagram like this:

Interact with the live diagram

Or if you input more complex code like this:

titanic.groupby(['Embarked', 'Sex'])['Pclass'].mean().unstack()

Pandas Tutor outputs a multi-step diagram like this:

Interact with the live diagram

If you want to explore further, scroll to the bottom of Pandas Tutor and click on one of the many examples.

Once you’ve understood an example, I’d encourage you to change the code and/or the data, and see if the diagram changes in the way that you expect.

You can even paste in your own data! Just open up any CSV file, copy the top few rows (including the header), and paste them in place of the multi-line "csv" string:

Related Projects

Tidy Data Tutor is very similar, except it’s for R code and the Tidyverse.

Python Tutor was created by the same author, and it allows you to visualize Python, JavaScript, C, C++, and Java code.

nbtutor is a Jupyter Notebook extension for visualizing Python code within your notebook.

How helpful was today’s tip?

🤩🙂😐


If you enjoyed this issue, please forward it to a friend! Takes only a few seconds, and it really helps me out 🙏

See you next Tuesday!

- Kevin

P.S. Whoa, you trained a neural net!

Did someone awesome forward you this email? Sign up here to receive data science tips every week!

Learn Artificial Intelligence from Data School 🤖

Join 25,000+ intelligent readers and receive AI tips every Tuesday!

Read more from Learn Artificial Intelligence from Data School 🤖

Hi Reader, Last week, I encouraged you to experiment with different LLMs, since there’s no one model that is superior across all use cases. Specifically, I suggested you try using Chatbot Arena, which allows you to chat with multiple models at once. It’s completely free, but has two significant disadvantages: Your chats are not private and may be used for research. It lacks the feature-rich interface provided by other LLMs. Today, I want to offer you a better method for experimenting with...

Hi Reader, Over the past 50 tips, I’ve touched on many different topics: Python, Jupyter, pandas, ML, data visualization, and so on. Going forward, I’m planning to focus mostly on Artificial Intelligence. I’m announcing this so you know what to expect, and I know what to deliver! 💌 I’ll also try to make the tips shorter, so that they're easier to digest on-the-go. Finally, I plan to include an “action item” each week, so that you can practice what you’re learning. I hope you like these...

Hi Reader, Next week, I’ll be offering a Black Friday sale on ALL of my courses. I’ll send you the details this Thursday! 🚨 👉 Tip #50: What is a "method" in Python? In Python, a method is a function that can be used on an object because of the object's type. For example, if you create a Python list, the "append" method can be used on that list. All lists have an "append" method simply because they are lists: If you create a Python string, the "upper" method can be used on that string simply...