Page 35 - Informatics_Practices_Fliipbook_Class12
P. 35

6.  Consider following two Pandas Series:

                 series1= pd.Series([1, 2, 3, 4, 5])
                 series2= pd.Series([10, 20, 30, 40, 50])
                  Determine the output on execution of the following Python statement: series1 + series2?

             Ans.  0    11
                  1    22
                  2    33
                  3    44
                  4    55
                  dtype: int64
               7.  Consider the following Pandas Series:

                 series= pd.Series([10, 20, 30, 40, 50]).
                  Determine the output on exceution of following Python statement: 30 in series.
             Ans.  True

               8.  Consider the following Pandas Series:
                  series = pd.Series([10, 20, 30, 40, 50])
                  Determine the output on execution of following statement: series.loc[2]
             Ans.  30


                  Case-based Questions


               1.  Suppose in a Company, the accounts manager needs to compute the total income for five employees in the company, given
                  their basic income and travelling allowance in form of Series as follows:
                  basicIncome = pd.Series([3000, 3500, 4000, 3200, 3700])
                  travelAllowance = pd.Series([500, 600, 400, 450, 550])
                  Help the accounts manager by writing a Python statement to calculate total income.

             Ans. import pandas as pd
                  basicIncome = pd.Series([3000, 3500, 4000, 3200, 3700])
                  travelAllowance = pd.Series([500, 600, 400, 450, 550])
                  # Calculate the totalIncome
                  totalIncome = basicIncome + travelAllowance
                  print('Total Income:', totalIncome)
               2.  Suppose the teacher-in charge of class XII wishes to calculate the gender distribution ratio of male to female students in her
                  class. She has access to the following gender details of ten students in class XII in the form of series object:
                  genderXII = pd.Series(['M', 'F', 'M', 'M', 'M', 'F', 'F', 'M', 'M'])
                  Help the teacher-in charge by writing a Python code snippet to compute the gender ratio.

             Ans:  genderXII = pd.Series(['M', 'F', 'M', 'M', 'M', 'F', 'F', 'M', 'M'])
                  # Calculate the count of male and female students
                  maleCount = (genderXII == 'M').sum()
                  femaleCount = (genderXII == 'F').sum()
                  # Calculate the gender distribution ratio
                  genderRatio = maleCount / femaleCount
                  print('Gender Distribution Ratio:', genderRatio)





                                                                                      Data Handling using Pandas  21
   30   31   32   33   34   35   36   37   38   39   40