Pandas Tutor visualizes how Python code transforms dataframes

Pandas Tutor lets you write Python pandas code in your browser and see how it transforms your data step-by-step. (If you use R, try Tidy Data Tutor. To visualize general Python, Java, C, C++, and JavaScript code, try Python Tutor.)

Why use this tool? Let's say you're trying to explain what this pandas code does:

(dogs[dogs['size'] == 'medium']
 .sort_values('type')
 .groupby('type').median()
)

Running this code in Jupyter shows only the input data and final result:

py_dogs_jupyter py_dogs_jupyter_after

But this doesn't tell you what's going on behind the scenes.

If you ran this same code in Pandas Tutor, you can teach students exactly what's going on step-by-step:

py_example.gif

Or if you're a student, you can use this tool to explore and learn on your own. Check out more examples below:

sorting by values
selecting a column
groupby + mean
grouping by multiple columns
groupby + multiple aggregation functions
selecting a column from a groupby
filtering for columns
filtering for rows
dropping columns
joining
merging
making a pivot table
melting
pivoting
stacking column index
unstacking row index
resetting index
setting index