Page 29 - Informatics_Practices_Fliipbook_Class12
P. 29

C T  08     Write Python statements to determine whether there exist an employee with id E004 in
                         series storing names and salary of employees.








                  in: Membership operator that allows us to check whether a particular value is present in series.



            1.5.6 Checking for Missing Values

            Many a times, some of the entries might be missing in the data because of value not known or even not applicable. Let
            us reconsider the following marks Series where the NaN indicates that the marks of student with roll number 302 is
            missing because he didn't appear for the exam:
             >>> import pandas as pd
             >>> marks = [90, 70, 95, 45, 100, 65, 78, 29, None]
             >>>  students = pd.Series(marks, index = [101, 102 , 103, 106, 107, 108, 201, 301, 302])
             >>> print(students)
            output:
                 101     90.0
                 102     70.0
                 103     95.0
                 106     45.0
                 107    100.0
                 108     65.0
                 201     78.0
                 301     29.0
                 302      NaN
                 dtype: float64
            Suppose we wish to determine if any students have been absent for the test by checking for the presence of missing
            values in the marksSeries, as demonstrated below:

             >>> students.isnull()
            output:
                 101    False
                 102    False
                 103    False
                 106    False
                 107    False
                 108    False
                 201    False
                 301    False
                 302     True
                 dtype: bool
            Now, we use above series of boolean indexes to retrieve the sub-series comprising only those values for which the
            index corresponds to the value True i.e. students who have missed the exam, as shown below:

             >>> boolIndex = students.isnull()
             >>> print(students[boolIndex])
            output:
                 302   NaN
                 dtype: float64





                                                                                      Data Handling using Pandas  15
   24   25   26   27   28   29   30   31   32   33   34