Page 10 - IPP-12-2024
P. 10

30.  Consider the following dataframe:                                                      [3]
                     NAME           CLASS  MARKS

                 0   Abhay            9       78
                 1   Rubina          12       90
                 2   Ramandeep   10           34
                 3   Sonam            9       95
                  Write suitable Python statements for the following:
                  (i)  Display names of all 9th class students.
                  (ii)  Add a new column called grade with the data ['B','A','E','A']
                  (iii)  Rename column NAME to SNAME.
             Ans.  (i)  df[df.CLASS==9]['NAME'] or df.loc[df.CLASS==9]['NAME']
                     or df.loc[df.CLASS==9,'NAME']
                  (ii)  df['grade']=['B','A','E','A']
                  (iii)  df.rename(columns={'NAME':'SNAME'},inplace=True)

                                                        Section D
              31.  Consider the table STUDENT given below, and answer the questions that follow:      [1+1+2]
                               RollNo      Name        Class     Gender       City       Marks
                                  1        Chetan       XI          M        Mumbai       430
                                  2         Geet        XII         F         Agra        460
                                  3        Preeti       XI          F        Mumbai       470
                                  4        Saniyal      XII         M         Dubai       492
                                  5        Manvi        XII         F        Moscow       360
                                  6       Nishant        X          M         Dubai       256
                  (i)  WAQ to display name in upper case.
                  (ii)  WAQ to display marks of the topper student.
                  (iii)  WAQ to count the total number of students of class XII.
                                                Or (Option for part iii only)
                  WAQ to count the total number of students gender-wise.
             Ans.  (i)  Select ucase(name) from student;
                  (ii)  Select max(marks) as 'TopperMarks' from student;
                  (iii)  Select count(*) from student where class = ‘XII’;
                                                           Or
                 Select gender, count(*) from student group by gender;
              32.  Mr. Narang, a data analyst, has designed the DataFrame df that contains data about sales containing year-
                 wise figures for five salespersons in INR with ‘Madhu’, ‘Kusum’, ‘Kinshuk’, ‘Ankit’ and ‘Shruti’ as indexes and
                 ‘Y2014’, ‘Y2015’, ‘Y2016’ and ‘Y2017’ as columns shown below. Answer the questions that follow:  [1+1+2]
                                 Y2014       Y2015        Y2016      Y2017
                 Madhu           100.5       12000        20000      50000
                 Kusum           150.8       18000        50000      60000
                 Kinshuk         200.9       22000        70000      70000
                 Ankit        30000.0        30000       100000      80000
                 Shruti       40000.0        45000       125000      90000
                  (a)  Predict the output of the following Python statement:
                      (i)  df.size
                     (ii)  df[2:4]
                  (b)  Write a Python statement to display the sales made by Madhu and Ankit in the year Y2015 and Y2017
                     column.
                                                           Or
                                                  (Option for part b only)
                  Write a Python statement to compute and display the sum of sales of years Y2015 and Y2017 column of
                 the above given DataFrame.
            A.32         Informatics Practices with Python–XII
   5   6   7   8   9   10   11   12   13   14   15