DataFrame Workout
- 02:20
Practice importing, exploring, and displaying data using Pandas in Python.
Downloads
No associated resources to download.
Transcript
Let's get some practice with Pandas dataframes. Before you start this exercise first make sure that you've saved the file stock data dot csv down to your computer.
In your Jupyter Notebook if you haven't already, first import pandas with the alias pd. Then import stock data dot csv into a new dataframe named stock data. Third, display the dimensions of stock data in a new cell display the first three rows of stock data, and then in another new cell display the last three rows of stock data.
Next, you first need to import pandas and use the alias pd so that it's easier to reference back to it. Under here, I'm creating the new dataframe stock data and I'm using the Pandas read CSV function. To do that here I have the file path to my data file, and this is gonna be different based on where you save the file on your computer. Make sure that you're copying that file path. And then when you paste it in, there's only gonna be a single backslash here and that's gonna cause a problem. So you need to backslash your backslash. Each of these should be a double backslash between each of these breaks in your file path. And then make sure that you have the name stock data, the name of that file, and then the correct file extension dot csv.
So that's going to create the new data frame stock data. And after that we're just going to display the dimensions of stock data with the shape attribute. So you can see that this dataframe is 100 rows by 7 columns.
Next, to keep getting to know our dataframe, let's display the first three rows. So I'm gonna write stock data dot head, and then the number 3 to indicate three rows. And that'll show me the first three rows of my dataset to see the last three rows. I just use the tail function, so stock data dot tail, and then I want the last three rows, and that'll show me the last three rows of my dataframe.