Creating Data Frames in Pandas
Zenva
ACCESS the FULL COURSE here: https://academy.zenva.com/product/bite-sized-coding-academy/
TRANSCRIPT
In this video we're going to get started with Pandas, and so learn a little about what the fundamental data structure for Pandas is as well as learning how to access a data using a thing called data frame. But first of all what we'll need to do is download the source code and we'll need to copy them into whatever working directory on your computer. 'Cause inside here we have these files that we'll need. So you'll have to copy these files over into your working directory. So I've already done this and created a folder called Pandas and I've copied over all of these things that we'll need. You'll want to open up your Anaconda Navigator and make sure you have the right environment selected and then we're going to launch Spyder. Okay, so lets get started. So we'll need to import Pandas, import Pandas as pd And I'm also going to import numpy as np just so that we're going to use it to populate data. We're gonna talk a little bit about Pandas, what the fundamentals data structure behind Pandas is. And the thing is called a DataFrame. And a DataFrame you can think of it as just being a single spreadsheet. A 2D table with rows and columns. So let's just create a DataFrame from just some data that we have. So remember it's a 2D table. So how I can define a dataframe is I can use a dictionary first, then give it to Pandas and say Hey, can you convert this dictionary into a dataframe. Each of the keys are going to be columns and the values are going to be rows. Column one, now I can just populate it with some random values, np.random.rand five. Essentially what I have done is created a single column and it has five rows. So let's just create this dataframe first so that we can see it. df equals, I can just create one by saying pd.DataFrame and I just pass it in this dictionary. Pass in now I've created a DataFrame. Let's see what this looks like. I can run this guy and you'll see I have column one and then just some random garbage values. So let's go a head and create another column, create another one and you'll see now we have three columns. And so this is just how we can give into or you can give data to Pandas into a dataframe just by using this dictionary where the keys are the columns and the values are going to be the actual values for that column. We'll see if we can fetch some rows and how we can fetch some columns. Index it like you would a list. So I'll say, let's get some, I'll run this and you'll see that we'll get the first two rows because remember that this goes, we start at zero and we go up two but not including this index. So we get zero and one. Instead we need to see what the column name is. So let's do col1 and what that will do is when I ... https://www.youtube.com/watch?v=z3-LGfjnZp8
8790378 Bytes