STAY WITH US

56. [Hindi]Machine Learning : .isnull() & .notnull() Method in Pandas| 2018 |Python 3


.isnull() & .notnull() Method in Pandas





56. [Hindi]Machine Learning : .isnull() & .notnull() Method in Pandas| 2018 |Python 3

                    All right in this lesson I'll introduce the is no and not null methods and these are complementary methods so they go hand in hand and they can be called directly on a series within our data frame and they're going to return different results depending on which method you call. But obviously they're going to check for the null status of every row and return true or false depending on whether that condition is met. So it's just another way that we can generate a Boolean serious for the purposes of filtering later. Let's begin by executing our code to import our employees GSV and store in the DNS variable. There I have my first three rows.

            Let's say I want to extract the rows from the data frame where the value in my team column is now so that any value that we're all familiar with by now. As always we begin by extracting that specific series. So our data from SDF in square brackets I write the name of the column I want to pull out there is my team here is there we have our end and values start to show up here. Whoops. Right here the second one. All right so the is no method called directly on the sea or the series here. And it is a method so we do have to have those parentheses at the very end and the Islam method works exactly as you'd expect if it is now it's going to return true if it's NOT know it's going to return false. So these any and values on rows 1 and 10. Keep an eye on them when I execute this method. You can see one in 10 here have become True's because the values in those rows are indeed not anything that's not know is going to return false. So now that we have a billion series of true and false is true where it is now false where it is NOT know we can pass this to a variable like mass. And now if I do my extraction by getting my data frame with the square brackets and putting in my billion series Inside there you can see I'm going to pull out all the rows where the value in the team column is now.


         See all the names here are populated. So I'm going to collapse this and move on and keep in mind as always that you know you can combine and mix and match these methods so you can use is no not no. Then you could pull in is in the you can pull in and now there are built in series with a direct comparison with the equality operator of double equals. You can combine and mix and match these along with the and and or operators that we introduced so these as long as you have the Boullion series you can always use it for the purposes of filtering that's really the key takeaway. And these methods basically simplify the process of creating a brilliant series for us as long as it's a boolean series it can be used one to one of the time or in combination with other Boyens series in
order to alter. So now that we have is now let's take a look at the not no method. And you can probably guess how it works as well. Let's take a look at the gender column now. Let's extract all the rows from RDF data frame where the value in the gender column is not null. So we have a valid value like male or female. So as always we begin by extracting the column we want to work with DMF which is our data frame gender in square brackets.


       There is our column and there are our values. So now I'm going to call the not null method on this. It is a method. It does require parentheses. No arguments though. So again the not null method is going to work in reverse the opposite of is no. If the value is not no and all of these so far are not now it's going to turn true. And whenever it does run into an end and value like here on row 20 it's going to return false because it is false that that values not now it is null. So when I execute this we'll see a bunch of trues. These represent all the valid genders in that column. And here we start running into the end ends and those show up as salsas. So nounless sort of in a variable. Let's keep things interesting and actually give it a different name just so we break out of that mask habit and you can see that it doesn't have to be that same variable. Going to be something arbitrary or whatever you want condition x y you know filter whatever you want. Actually I'd probably avoid Seltzer's that's a python key word but let's do condition let's put it in our square brackets. And now we've extracted the rows from the data frame where the value in the gender column is not now. So now we basically remove the values with the rows with no values in the gender column. Pretty simply two lines of code. Imagine operating this on something like five million rows in a huge colossal data set. Pretty effective to do this in simply two lines so very effective.

     So these are the complimentary is null and not null methods. Call them directly on a series to return a brand new boy in series. The method will give you the truth. If it is no and false otherwise do not know that it will give you True's if the real value is not known. Which means it's a valid string or integer or so on. And the ABA says while the not null method will give you a false if the value is no. So these are the two complementary methods feel free to play around with them and use them. And in the next lesson we'll continue exploring different methods that we can use to return Boolean series.
For the purposes of filtering.

Code Download Link : ML56

Code : 

#!/usr/bin/env python
# coding: utf-8

# In[4]:


import pandas as pd

df = pd.read_csv("employees.csv", parse_dates=["Start Date","Last Login Time"])
df["Senior Management"] = df["Senior Management"].astype("bool")
df["Gender"] = df["Gender"].astype("category")
df.head()


# In[7]:


mask = df["Team"].isnull()

df[mask]


# In[9]:


condition = df["Gender"].notnull()
df[condition]


YouTube Video :


Post a Comment

0 Comments