DAY-6 Unlock Your Data: Powerful Techniques in pandas

Akansha Yadav demonstrates pandas methods to explore DataFrames: df.sample for random rows, nunique and unique for distinct values, isnull and notnull for missing data, value_counts for frequency, and idxmax and idxmin for extreme values.
Chapters
Hello everyone, welcome back to my YouTube channel. In today's video, we will be talking about again the view methods, that how to view your data effectively, how to get access to all the things from the data, how to know your data better. So, and we have already created a part 1 where we discussed about few basic methods. Now let's see what are we going to do in this one. So in the last video, we learned about how to read any file. So we are going to read a CSV file. In the last video, I told you if you get any Unicode error, you can write r to avoid that error. So the very first method that we have today is the sample. Suppose you wanted to generate a sample of 5 different data, but that should be the random one. I don't want first 5, last 5, or mid one. I just want a random one. So what you have to do is you have to use df.sample brackets n is equal to 5. If you want 5, you can write 5. If you want more than that, you will write more than that. And that's how it will give you the output, which is 83, 121, 292, 21, 410. That's the random generated data. I will show you, is it generating the random data every time or not? So once I have run this, I got output. Now I'm re— pressing the run button. Now we get the random values again. Now the values are changing. And the method is you can count the number of unique values in each column. If you wanted to count the number of unique values, what you have to do is you have to use nunique. NUNIQUE. NUNIQUE is a function which will come up with the empty brackets parenthesis. N stands for number and the unique— number of unique values in each column. If you will run this, you will get the data which consists of some numerical values, which is also the value count of the unique numbers, unique values. It can be any— we have 457, it means these are the unique values in team, 53 position, 5 age, 22 and so on. That's how the unique values are printed. Suppose you wanted to know in that particular, um, what are the unique values, which values are unique, print those values. So what you can do is you can use .unique method. In this case, n will not come. In this case, you have to write df, then in the brackets you will write down the column name from which you wanted to print the unique values. So out of these, you can write any. I have written team, which has 30 columns unique. So these are all the 30 columns which are unique from the teams column. That's how the output is generated. You wanted to change the column name, then you can change it as well. I will show you with one more. So suppose we have name, team, number, position. So in this case, what I am going to do is I will be using position because it has the minimum value. So I am going to replace it with position. So position, we have the string, so let's replace it with the position. So in position we have PG, SF, SG, PF, C. These are the 5 values which are printed from this unique. Another method is to check any missing value. There are the data which consist of thousands or lack of rows, then how you are going to check for the missing values? So for that you can use 2 methods. One is using isnull, another one is using notnull. Isnull will give you the output of missing values. Not null will also give you the output of missing values. So isnull, let's see what isnull is. Null will give you the output accordingly. Like suppose if there is a value, then it will return false. If there is a missing value, it will return true at that place. Missing value true, not missing value false. But in case of not null, it will be opposite of that. It means wherever there is a value already present,, then that will be true. If there is any missing value, it will keep it as false. The another method is to check how many value counts are there. That particular unique value is repeated how many times. So for that you will use df bracket the age.value_count is also a function. You will use the brackets. Once you have written the brackets, you can run this command. And once you will run it, you will get the values where we will have the column values. It means unique values and on the right-hand side you will get values which is the numbers that this is the number that particular value is repeated. I will show you, in, in case of age we have 24 which is repeated 47 times, which is another one is 25 which is repeated 45 times, 27 is repeated 41 times, and so on. So that is giving you the value count of occurrence. Another method is idxmax. Idx_min, it means minimum index, well, index label, returns the index label of the minimum value in the column, that where that particular value is present and what is the index. Where is the minimum value is present in the age column and what is the index of that? So it's giving you 298 where the minimum value of the column is present and 122 where the max sorry, opposite. And this is the maximum and then the minimum. So that's how it works. These all are the methods using which you can view your data effectively. If you have not watched the first part, go check it out. And if you like this video, don't forget to hit the like button, subscribe to my channel, and comment down your views. I've been waiting for you in the comment section. Bye-bye.










