From the course: Data Cleaning and Manipulating with Python in Excel

Dataframes

- [Instructor] One of the first things you'll see when working with Python is something called a data frame. So you may be wondering what is a data frame? A data frame is essentially a table with rows and columns similar to a spreadsheet or table you'd find in Excel. It allows us to store and manage data sets with ease. It supports fast and efficient data manipulation, aggregation, and transformation operations. Perfect for working with data sets within Excel. I want to run through some examples on how to create a data frame using Python in Excel and how to execute the Python code as well. So let's open up the exercise file for this video. We'll use the Chapter 1_01 underscore zero one tab. Here we have two data sets. One is data within a table structure and one without. I want to show you this so we can understand what the code looks like when we make our data frames. So let's start off with the raw data first. So we're going to go into J1 and we're go to the formulas tab and click insert Python. And right here is where we can commit our Python code to create our data frames. So we're going to name our data frame, we're just going to do DF1 equals, and we have to choose the range for our data frame. We're going to go to A1, drag across and down all the way down to G11. And looking at the code really quickly, we see here A1 to G11, which is the range for our data frame and headers equal true. What that means is the first row in our data frame will be the headers for the data frame. To commit this, we will do control enter. Okay, awesome. We have our first data frame already set up. Now let's take a quick preview at this by clicking into it and what this will show us is a quick preview of what our data frame looks like. Now I wanted to print this as an Excel value. What you do here is right click right into it, go down to Python output, and click Excel value. Awesome. So what I'm going to do really quickly is adjust the columns for everything, make sure everything's okay and perfect, there's our data frame right there from our raw data set with everything that we have from our original data we had. So now I want to do is do the same thing but with the data within the table. So I'm going to go right down to J15, go to insert Python, and for this one, I'm just going to call it DF2 equals, I'm going to choose the entire range, and you're going to see things a little bit differently in the code. We see right there with the range before, this one says table one and then brackets all. What that does is it'll tell you the exact table name that we chose and then also the columns. Since we chose all of the columns within the table, it'll say the word all and same thing applies for headers equal true. Do control enter to execute this. After I just printed the Excel value for a second data frame, we could see that they both came back with the same result and we have ourselves some data frames to work with. That's a great job so far and this will help us get started in this course. I appreciate you following along and I look forward to seeing you on the next video.

Contents