Python. A family of non-venomous snakes found in Africa, Asia, and Australia. Also a programming language. Today we’ll be talking about the latter! Excel recently released Python in Excel, and this game changer allows us to leverage all of Python's tools within our worksheet.
Let’s take a look at how we can use Python in Excel to visualize sales data. Check out the gif above - first, we need to store our data as a Python data frame so that Python is able to read it. To create a Python data frame, we’ll select the cell where we’d like the frame to live, then activate Python by typing =py( - then give the data frame a name. We need a name to reference this frame in our code! We’ll name this data “data” and set the name equal to our data range by typing an equal sign and selecting the data. Now that we’ve defined our data, we’ll press CRTL ENTER to create the frame.
Now the fun part! Let’s write some code!! We’ll create a line chart in this example - first we’ll select the cell where we want our line chart to populate, then we’ll activate the Python editor by typing =PY( and then enter the code data[“Sales”].plot(kind=”bar”), and press CTRL ENTER to create the chart. Finally, we need to switch the output to an Excel value by opening the Python output dropdown and selecting Excel Value to view our chart!
It’s a little hard to see at first…our chart is stuck inside of that tiny cell! We can merge a few cells together to enlarge our chart. Much better! If you want to learn more about using Python in Excel, check out our full YouTube tutorial here to master the basics 🐍.