Day 9 Pick Your Pandas: Mastering Selection Techniques

Akansha Yadav shows how to filter and select data in pandas using an NBA dataset. Learn Boolean indexing to find null values, .loc for label-based selection, and .iloc for position-based selection with integer positions.
Chapters
Ladies and gentlemen, hello everyone, welcome back to my YouTube channel. In today's video, we will see how to do selection using pandas in Python. So let's get back on the screen and start. Selection is basically a process using which we are going to extract a small subset of the data from either from the DataFrame or the series. So based on the criteria, based on the conditions, we are going to do it. So there are multiple operations using which you can do this. So first is the filtering rows and columns based on condition using indexing. Then you can use the slicing method as well. So here we have the data which we have used in the last video as well, which is NBA.csv. Then I have printed this data where we have the name, team, number, position, age, height, weight, college, and salary columns. So now see how to do the Boolean indexing. So using Boolean indexing, let's see how we can extract it. So Boolean indexing is basically when you want to work with the true and false values. So what I want is I want to select the players with the null values in the college column. That how, uh, I want to print all these things where the missing values are there in the college. So for that, what I have done is here I have written the indexing that from data, the data, then from data college column, then .isnull. isnull I taught you in the, uh, I think 6th or 5th video where we were discussing about how to view the DataFrame, how to view your data effectively. So there I told you that what is isnull and why do we need it. So isnull is basically a method within the pandas library using which you can check which value— where the values are null values and where the values are already there. So if you can see over here, it printed all the rows where the college values are missing. So these are the rows you— where the column college values are missing. Another way to do it using loc. So loc method is the one which says that it is label-based indexing. Label-based indexing means you have to write down the name of that particular thing. So suppose I want to select the rows with the label 0 to 2 and column name to position. So column name to position and label 0 to 2, it means row with the 0 to 2. So what I have to do is I have written data.loc, then applying the row 1. So row says 0:2, which means I am writing the indexes of the row. And second time what I am doing is I am writing the column names name and position. I am using the colon, which denotes that I want from this to that. It means everything between name and position will be printed along with the name and position. So if you can see over here, output name, team, number, and position we are getting as an output. And if you will see from the row side, we have 0, 1, 2. So that's how you can do the slicing. Another way is using iloc method. So iloc is basically when you want to do the index-based, uh, an index-based basically selection. So index-based basically it means you have to write down 0, 1, 2, 3. It means you are going to deal with the numbers only. You are— you cannot write the label, it means the name assigned that particular thing. Now what I want to do is I want to select the rows from the index 0 to 2 and the column for indexes 0 to 2. It means from row side also I want 0 to 2, from column side also I want the same. So what I have to do is I have to write down the indexing. So whenever we do the indexing, it means when we are working with a numerical value within the index concept, then in that case what you have to do is if you want 2 output, then you have to write 3. Just like over here I have written data.iloc brackets 0:3 means I want up to 2. Same I have done for the columns as well. And here we got the output name, team numbers, and which is 0, 1, 2, and same way 0, 1, 2. So that is how you can do the selecting. I hope you get this. I, I hope you get this concept. And if you like this video, don't forget to hit the like button and subscribe to my channel for more informative videos on pandas, on data analysis, data scientists, and machine learning. So, bye-bye!










