XII IP Class Test Pandas
XII IP Class Test Pandas
4 Write a program to create a series object using a dictionary that stores the number of
students in each house of CLASS 12D of your school.
Note: Assume four house names are Beas, Chenab, Ravi and Satluj having
18, 2, 20, 18 students respectively and pandas library has been imported as pd.
W-2
12 Which attribute is used to get total number of elements in a Series?
a. size b. itemsize
c. shape d. ndim
13 To display last five rows of a series object ‘S’, you may write:
a. S.Head()
b. S.Tail(5)
c. S.Head(5)
d. S.tail()
14 To display top five rows of a series object ‘S’, you may write:
a. S.head()
b. S.Tail(5)
c. S.Head(5)
d. S.tail()
15 method in Pandas can be used to change the index of rows and
columns of a Series or DataFrame:
(i) rename() (ii) reindex() (iii) reframe() (iv) none of the above
16 CSV stands for
17 Pandas Series is:
a. 2-Dimensional b. 3-Dimensional c. 1 Dimensional d. Multidimensional
18 Python pandas was developed by:
a. Guido van Rossum b. Travis Oliphant
c. Wes McKinney d. Brendan Eich
19 The command to install the pandas is:
a. install pip pandas b. install pandas
c. pip pandas d. pip install pandas
20 The name “Pandas” is derived from the term:
a. Panel Data b. Panel Series
c. Python Document d. Panel Data Frame
21 We can analyse the data in pandas with
a. Series b. Data Frame
c. Both of the above d. None of the above
22 Pandas is a:
a. Package b. Language
c. Library d. Software
23 Which of the following import statement is not correct?
a. import pandas as CLASS12 b. import pandas as 1pd
c. import pandas as pd1 d. import pandas as pd
24 Which of the following is not an attribute of pandas data frame?
a. length b. T
c. Size d. shape
25 import pandas as pd
s=pd.Series([1,2,3,4,5], index=['akram','brijesh','charu','deepika','era'])
print(s['charu'])
a. 1 b. 2 c. 3 d. 4
26 Assuming the given series, named stud, which command will be used to print 5 as
output?
Amit 90
Ramesh 100
Mahesh 50
john 67
Abdul 89
Name: Student, dtype: int64
a. stud.index b. stud.length
c. stud.values d. stud.size
27 A social science teacher wants to use a pandas series to teach about Indian historical
monuments and its states. The series should have the monument names as values and
state names as indexes which are stored in the given lists, as shown in the code. Choose
the statement which will create the series:
import pandas as pd
Monument=['Qutub Minar','Gateway of India','Red Fort','Taj Mahal']
State=['Delhi','Maharashtra','Delhi','Uttar Pradesh']
a. S=df.Series(Monument, index=State)
b. S=pd.Series(State, Monument)
c. S=pd.Series(Monument, index=State)
d. S=pd.series(Monument, index=State)
28 Difference between loc() and iloc().:
a. Both are Label indexed based functions.
b. Both are Integer position-based functions.
c. loc() is label-based function and iloc() integer position-based function.
d. loc() is integer position-based function and iloc() index position-based function.
29 Method or function to add a new row in a Series is:
a. .locate() b. .loc()
c. join d. add()
30 Rasha wants to set all the values to zero in Series, choose the right command to
do so:
a. S1=0 b. S1[]=0
c. S1[:]=0 d. S1[:]==0
31 Write the output of the given program: import pandas as pd
S1=pd.Series([5,6,7,8,10],index=['v','w',' x','y','z'])
Output required (5,)
a. print(S1.shape()) b. print(S1.shape)
c. print(S1.values) d. print(S1.size())
32 To check if the Series object contains NaN values, attribute is display.
a. hasnan b. nbytes
c. ndim d. hasnans
33 Consider the following series named animal:
4 import pandas as pd
St={‘Beas’ :18, ‘Chenab’ :20, ‘Ravi’ :20, ‘Satluj’ :18} S1=pd.Series(St)
5 d. Error
6 [40 50 60 70]
7 2 55
dtype: int64
8 B 2
D 4
F 6
dtype: int64
9 0 False
1 False
2 True
3 False dtype: bool
10 0 35
1 45
2 25
3 25
dtype: int64
27 d. S=pd.Series(Monument,index=State)
28 c. loc() is label based function and iloc() integer position based function.
29 b.loc()
30 S1[:]=0
31 b. print(S1.shape)
32 (d) hasnans
33 W Wolf B Bear
dtype: object
34 x NaN
a NaN
v -1.0
w 2.0
y 2.0
z 8.0
dtype: float64
35 2 Raj
5 Ankur
6 Harsh dtype: object
2 Raj
5 Ankur dtype: object
36 0 Dance
1 Music
2 300
3 400
4 500
37 Color[2:5:2]
38 12
39
40 0 5
1 6
2 7
3 8
4 9
41 i) India NewDelhi UK
London
Japan Tokyo dtype: object
ii) CapCntry[5:1:-1] China Beijing
Japan Tokyo
France Paris
UK London dtype: object
iii) CapCntry[: :-1] China Beijing
Japan Tokyo
France Paris
UK London
USA WashingtonDC
India NewDelhi dtype: object
iv) CapCntry[3:] France
Paris
Japan Tokyo
China Beijing dtype: object
42 Line1: import pandas as pd
Line2: import_numpy as np # Library name
Line3: A=np.array(2,11,2) # function name to get numpy array
Line 4: S=pd.Series(_A , Index=[_0,1,2]) # Data name and indexes
Line 5: Print(S)