QP - Info - Gr.12 - June MT - 2022 - QP
QP - Info - Gr.12 - June MT - 2022 - QP
I
D
T
ERM EXAMINATION, JUNE 2022
SUBJECT: INFORMATICS PRACTICES (065)
Grade : 12 Time: 3 Hours
Date: 17/6/2022 Max. Marks : 70
General Instructions:
1. The question paper is divided into 2 Sections – A and B.
2. Section A consists of 10 MCQ Questions
Questions (1-10) - 1 mark each question
3. Section B consists of 21 Descriptive Questions
Questions (11-19) - 2 marks each question
Questions (20-25) - 3 marks each question
Questions (26-31) - 4 marks each question
4. All questions are compulsory.
Section A
Multiple Choice Questions(1-10) – 1 mark each
1 Write the Python code to create a Series S that would print the scalar value 100, 1
five times with index values 1,2,3,4,5.
2 Choose the correct attribute which is used to assign a name to the index of the 1
series.
a) name
b) series.name
c) index.name
d) values
1
4 ______________ is used to print the number of values in Series S. 1
a) S.count
b) S.ndim
c) S.values
d) S.size
a) loc()
b) iloc()
c) insert()
d) del()
Output 1 Output 2
Output 3 Output 4
a) Output 4
b) Output 1
c) Output 2
d) Output 3
Write the command which will display the name of the furniture having rent>250,
2
based on the output given below.
Output:
a) print(Samt[Samt>250])
b) print(Samt(Samt>250))
c) print(Samt[Samt>=250])
d) print(Samt[Samt<250])
import pandas as pd
p=pd.Series([ 'a','b','c','d','e'])
p=p.drop([0,2,4])
print(p)
a) 1 b
2 c
b) 1 b
3 d
c) 3 d
1 b
d) 2 c
1 b
10 Given the following code and the Output, Fill in the blanks (blank1 & blank2) with 1
attributes.
3
Output:
2
(3, 3)
A. blank1 is index and blank2 is size
B. blank1 is size and blank2 is dim
C. blank1 is dim and blank2 is shape
D. blank1 is ndim and blank2 is shape
SECTION B
11 Write the code that would generate a ndarray called Arr with values [ 1 3 5 7 ] 2
using arange() function and display the ndarray.
12 Write the code to create the DataFrame given below (using Dictionary): 2
13 Identify the errors and re-write the code given below which would display the first 2
4 employee numbers & last 5 employee numbers.
4
15 Identify the errors and re-write the code given below: 2
16 Write the code to create the Series given below (using List): 2
import pandas as pd
Dic={'empno':[101,102,103,104],'name':['anil','beny','cyril','dravid'],
'salary':[3000,5000,8000,9000]}
df=pd.DataFrame(Dic,index=['A1','A2','A3','A4'])
print(df.loc['A2':'A3'])
print(df.loc[['A1','A3'], :])
import pandas as pd
emp={ 'Name':['Sachin','Vinod','Rajesh','Sharma'],
'Salary':[2000,5000,4000,7000] }
df=pd.DataFrame(emp)
df1=df.drop([0,2],axis=0)
print(df1)
5
20 Write the Output for the following code: 3
import pandas as pd
c=['red','green','blue','pink','black','white']
p=pd.Series(c,index=['r','g','b','p','k','w'])
print(p[:4]) #output 1
print(p[: : 3]) #output 2
print(p[-1:-5:-1]) #output 3
22 Consider two objects x and y. x is a list whereas y is a Series. Both have values 20, 3
40, 90, 110. What will be the output of the following two statements considering
that the above objects have been already created.
23 Write the code to create the following Dataframe "Product" using Nested lists (List 3
of lists) and display the DataFrame.
import pandas as pd
import numpy as np
arr1=np.array([10,20,30])
arr2=np.array([-10,-20,-30,-40])
arr3=np.array([100,200])
df=pd.DataFrame([arr1,arr2,arr3],columns=['A','B','C','D'])
print(df)
6
25 What would be the output of the following? 3
import pandas as pd
list1=[100,200,300,400,500]
list2=[200,400,600,800]
P1=pd.Series(list1,index=['A','B','C','D','E'])
P2=pd.Series(list2,index=['E','F','C','D'])
print(P1+P2)
26 i) Ritesh wants to display the last 4 rows of the dataframe df and has written the 1
following code :
df.tail()
But last 5 rows are being displayed. Identify the error and rewrite the correct code
so that the last 4 rows get displayed.
import pandas as pd
empdata={'empid':[101,102,103,104,105,106],
'Doj':['12-1-12','15-1-12','5-9-10','17-1-12','5-9-17','16-1-12']}
df=pd.DataFrame(empdata)
print(df.tail(2)['Doj']) #output1
print(df.head(7)['empid']) #output2
print(df.tail()['empid']) #output3
Dataframe df:
Code:
ii) Write the appropriate code(s) that would modify the dataframe df given in (i) 2
7
and display the new Dataframe as follows:
29 i) Given the code that creates Series from ndarray and the Output, Fill in the blanks 2
(blank1 & blank2).
Code:
Output:
8
30 i) Consider the following DataFrame df. 2
ii) Given the following code that creates Dataframe from Series and the final 2
Output, fill in the blanks (blank1 & blank2).
Final Output:
31 i) Complete the given program by writing the code (in the blank lines) that would 2
set the columns as 'name' and 'marks' for the DataFrame df that is given in the
program and display the DataFrame df. (Output of the final program is also given
below)
Program:
import pandas as pd
lst=[[ 'Sonu',95],[ 'Binu',97],[ 'Renu',88],[ 'Tanu',72]]
df=pd.DataFrame(lst,index=[ 'stud1', 'stud2','stud3','stud4'])
--------------------------------------
9
--------------------------------------
name marks
stud1 Sonu 95
stud2 Binu 97
stud3 Renu 88
stud4 Tanu 72
*******************************************************************
10