Python Tutorial: Welcome to Python

Chris Cardillo teaches Python basics for spreadsheet users, starting with how packages work using dot notation. You'll learn to import pandas, load an Excel file into a DataFrame, assign it to a variable, and print the results.
Chapters
Hi, welcome to Python for Spreadsheet Users. My name is Chris Cardillo and I'll be your instructor for this course. Python is a general purpose programming language, meaning it helps run everything from websites to self driving cars. Python has amazing code packages for working with data, but most fundamentally, Python is an object oriented programming language. This is a fancy way of saying in Python one thing is usually located inside another thing. In spreadsheets you're probably familiar with functions like sum to add numbers. This function is actually located inside the math package. Or and maybe you're familiar with Vlookup index and Match. These functions are all located inside the lookup package in Python. Let's say there was also a package called Math, and inside this math package there was a function called sum. Just like in spreadsheets. To access the sum function inside the math package, we'd write math sum and then place numbers inside the function. Here we'd expect a result of five. That dot lets us access a function inside of the package, one thing inside another thing, and that's Python. In Python, we tell a computer what to do with a script. A script is a series of instructions ran in a specific order that creates a desired outcome. They're like recipes. At the beginning of these scripts, we'll often import packages like our math package. Let's import a package from Python that will allow us to load in and manipulate our data. A package called Pandas. Yes, Pandas. To use Pandas, we write import Pandas. We write this line in all lowercase letters because Python is case sensitive. On the next line after we import Pandas, we'll load our Excel data into Python. Pandas likes data with rows and named columns. Like the example here, we have three columns. A fruit's name, color, and how much it costs in US dollars. Each row is a different fruit. This is the kind of tidy data Pandas likes to load. In our Excel data, we'll use the readexcel function in the Pandas package. And to access the function inside of the package, we'll use the dot pandas read underscore Excel. Our file name goes inside the function in quotes. And now we can import Excel data into Python. Before we continue, it's common practice to import Pandas as pd. This lets us reference the Pandas package with PD instead of writing out Pandas all the time. Now we we can just write PD readexcel instead. Now our data needs somewhere to live because we'll have to reference it later on. So we'll assign it to a variable. Assignment is as intuitive as fruit PD readexcel xlsx. You can call variables anything, usually something meaningful. They just have to start with a letter and can't have spaces or special characters. It's common to use an underscore to substitute for spaces, though. Finally, to look at all of our data, we can use Python's built in print function at the end of our script. This function does not require any dot accessing, we simply write print and pass the variable fruit to the function. This will display all of our data in the console. The console at the bottom of this image will display the results of your script in the upcoming exercises. You will also learn how to interact with it directly later on. Now it's your turn to write some code.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







