Page 91 - Informatics_Practices_Fliipbook_Class12
P. 91

Previous Years' Questions


               1.  What will be the output of the following code?                                              [2023]

                  import pandas as pd
                  myser pd. Series ( [0, 0,0])
                  print (myser)
                  a.  0 0                       b. 0 1
                    0 0                             0 1
                    0 0                             0 2
                  c.  0 0                       d. 0 0
                    1 0                             1 1
                     2 0                            2 2

             Ans.  c. 0 0
                    1 0
                    2 0
               2.  Which of the following is a two-dimensional labelled data structure of Python ?
                  a.  Relation                                    b. Dataframe
                  c.  Series                                      d. Square
             Ans.  b. Dataframe
            Q. 3 is ASSERTION (A) and REASONING (R) based questions. Mark the correct choice as                [2023]
                  a.  Both (A) and (R) are true and (R) is the correct explanation for (A).
                  b.  Both (A) and (R) are true and (R) is not the correct explanation for (A).
                  c.  (A) is true and (R) is false.
                  d.  (A) is false but (R) is true.
               3.  Assertion (A): The output of addition of two series will be NaN, if one of the elements or both the elements have no
                  value(s).
                  Reasoning (R): While performing mathematical operations on a series, by default all missing values are filled in with 0.
             Ans.  c.  (A) is true and (R) is false.
               4.  Carefully observe the following code:                                                       [2023]
                  import pandas as pd
                  dic={ 'pid' : [101, 102, 103, 104, 105],
                  'pname':['Shyam', 'Roushan', 'Archit', 'Medha' , 'Lalit'], 'sports':['Cricket', 'Tennis',
                  'Football', 'Cricket', 'Cricket'], 'points': [45000,20000, 15000, 53000,60000]}
                  player=pd.DataFrame(dic)
                  print(player)
                  Write Python statements for the following:
                  (i) In the dataframe player created above, set the row labels as 'Player1′, Player2', 'Player3′, "Player4', 'Player5'.
                  (ii) Rename the column 'points' to 'netpoint' in the DataFrame player.

             Ans.  (i)  #Method 1
                    index=pd.Index(['Player1','Player2','Player3','Player4','Player5'])
                    player=player.set_index(index)
                    #Method 2
                    player=pd.DataFrame(dic,index=['Player1','Player2','Player3','Player4','Player5'])


                                                                             Data Handling using Pandas DataFrame  77
   86   87   88   89   90   91   92   93   94   95   96