Legacy – Selecting Index Workout
- 02:52
Workout demonstrating how to index the rows of the dataset in the Pandas library.
Downloads
Transcript
We now work with a new data set, which is again s&p 500 data which consists of changing values, the highest value, and the lowest value over a certain period of time. For this will be again using the pandas library. So as usual, we will import pandas as PD. So now first we need to load the data set. So again, we'll name the data set as SP 500. Standard PD . read underscore CSV. And we'll run it perfect, it returned without any errors. Let's now print the data and have a quick look at it.
As you can see, it's the opening value, highest value, lowest value, closing value over a certain period of time. Again, in this case, we are looking to clean the data set as part of the pandas library. So the first thing that we look to do is to select and locate the index of the data set. So let us try printing the data index it says there are 23 indices, it starts from zero goes till 23. And it increases by step. So one, we would like to locate a zero, the zero index and it says that the zero index is the 11, 12 2019 value which is perfect. So the LOC value locates a certain index, we can also change the indexing of the columns. So when loading the data set, we can say index column zero, so it goes on based on the date. And if we load that, in this case, the date or the indices, so essentially, we can locate certain values based on the date. So we can save print SP 500 . loc of the particular date. So we can say we want the value at 11, 8 2019 And we run it oh there's an error what made the mistake be the mistake is we didn't select the value in quotation marks. Now there shouldn't be an error returned. Perfect. So the opening value closing value the highest lowest on this particular date is stated over here.