0% found this document useful (0 votes)
518 views33 pages

101 Onwards On Python Pandas and Pyplot

This document provides 101 multiple choice questions to test knowledge of Python Pandas and Matplotlib. It includes questions about sorting and filtering DataFrames, selecting rows and columns, basic operations like counting rows, and conceptual questions about DataFrame attributes. The questions are in a case study format where a DataFrame is provided and the reader is asked to select the correct code to perform an operation on it, such as arranging rows by name or finding records below a salary threshold.

Uploaded by

pubg boy AS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
518 views33 pages

101 Onwards On Python Pandas and Pyplot

This document provides 101 multiple choice questions to test knowledge of Python Pandas and Matplotlib. It includes questions about sorting and filtering DataFrames, selecting rows and columns, basic operations like counting rows, and conceptual questions about DataFrame attributes. The questions are in a case study format where a DataFrame is provided and the reader is asked to select the correct code to perform an operation on it, such as arranging rows by name or finding records below a salary threshold.

Uploaded by

pubg boy AS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

101 ONWARDS MCQ FOR XII AB STUDENTS ON PYTHON PANDAS AND PYPLOT

Case study based questions

Anil has created a dataframe df which he wants to manage according to given questions.

EmpNo Name Salary


0 E01 raj 1000
1 E02 Sohail 1200
3 E03 Sameer 1800
4 E04 Kunal 1600
5 E05 John 1400

Help him by selecting correct options for given questions.


106.Anil wants to arrange and display data based on Name in descending order. What code
should he write?
a) df.sort_values(by='name' ,ascending=False)
b) df.sort_values(by='name,asc=False)
c) df.sort_values(ascending=False)
d) df.sort_values('name',asc=False)
Ans:a) df.sort_values(by='name' ,ascending=False)

107. He wants to find all the records with salary less than 1500. He should write?
a) df.salary(data<=1500)
b) df[df.salary<=1500]
c) df['salary'<=1500]
d) None of the above
Ans: b)df[df.salary<=1500]

108. He is asked by his friend to display last 3 rows. What code he should write?
a) df.iloc[-3:]
b) df.loc[-3:]
c) df.tail(3)
d) a,c
e) all
Ans: d) a,c

109. He wants to count total elements of given dataframe. Which command he should choose?
a) df.count()
b) df.values
c) len(df)
d) df.size
Ans: d) df.size
110. Select correct command to delete column 'EmpNo'.
a) df.drop('EmpNo')
b) df.drop('EmpNo',axis=0)
c) df.drop('EmpNo',axis=1)
d) None
Ans: c) df.drop('EmpNo',axis=1)

111. His boss asked him to reset the dataframe with value 0. How can he do this?
a. df.loc[:]=0
b. df.at[L]=0
c. df = 0
d. None of above
Ans: (a) df.loc[:]=0

112. (i) A dataframe can be called as tabulated labeled array.


(ii) A dataframe can be compared with spreadsheet where each
value is Identified by row and column index.
a. (i) true, (ii) false
b. (i) false, (ii) true
c. Both are true
d. Both are false
Ans: (c) Both are true
113. Look at the anatomy of dataframe and select option that represents correct terms for given
numbered circle.

(a) 1--axis = 0, 2--axis = 1, 3-- Missing Value


(b) 1--axis = 1, 2--axis = 0, 3-- Missing Value
(c) 1--axis = x, 2--axis = y, 3-- Missing Value
(d) 1--axis = y, 2--axis = x, 3-- Missing Value
Ans: (a) 1--axis = 0, 2--axis = 1, 3-- Missing Value
114. What will be output of the following code?

List1 = [{10,20], [30,40], [50’60]]


Df = pd.Dataframe(list1)
print(df)

(a)
10 20

0 30 40

1 50 60

(b)
0 1

10 30 50

20 40 0

(c)
0 1

0 10 20

1 30 40
2 50 60

(d)
0 1 2

0 10 30 50

1 20 40 60

Ans: (c)
115. Consider the following dataframe ‘emp’

ename dept

e1 a.k. om

e2 m.s. ee

Which type of error following code will produce:


Emp.loc[:, “sal”] = [200,300,400]

(a) Key error


(b) value error
(c) syntax error
(d) no error
Ans: (b) value error

116.Charan has declared a Numpy array:


n= np.array([150,160],[80,90])
He wants to make a dataframe with his own column name and index name.Help him select
correct code.
(a) df = pd.DataFrame(n, index = ['A','B'], column = ['C1','C2’])
(b) df = pd.DataFrame(index = ['A','B'], column = ['C1', 'C2’'], n)
(c) df = pd.DataFrame(n, column = ['C1','C2’], index = ['A','B'])
(d) All are correct
Ans: (d) All are correct

117.In the following questions two statements are given-


one assertion denoted with (A) and other reason denoted with (R).
Select the correct answer as per given choices.
(a) Executing following code
df=pd.Dataframe([23,43], index=['True','False']
print (df[True])
Will produce key error.

(r) Dataframe does not support Boolean Indexing.


a. (A) is False but (R) is True
b. (A) is True but (R) is False
c. Both are True but (R) is not correct explanation of (A)
d. Both are True and (R) is correct explanation of (A)
Ans: (b) (A) is True but R) is False

118.For given dataframe


Jhelum Ravi
Rno 1 7
Name sundar satya

Python will store data for 'jhelum' column as


a. Float
b. Int
c. String
d. Object
Ans: (d) Object

119.Which of the following is not true about dataframe?


a. A dataframe object can be created by passing dictionaries.
b. A dataframe is size immutable.
c. A dataframe index can be string.
d. A column of dataframe can have data of different types.
Ans: (b) A dataframe is size immutable.

120.What will be output of following code:


import pandas as pd
I = ([so, no, go, do, to])
df = pd.DataFrame(I)
print(df[-2:])

(a) 2 go (b) 3 do c) 4 to (d) 0 so


1 no 4 to 3 do 1 no
0 so 2 go

Ans: (b) 3 do
4 to

121:Which of the following is not an attribute of dataframe:


(a) axes
(b) empty
(c) transpose
(d) size

Ans: (c) transpose


122. To count total no. of rows of dataframe ‘df’ which of the following command can be
written:
(a) len(df)
(b) df.len
(c) df.len()
(d) All are correct

Ans: (a) len(df)

123.Select the correct statement to change rows as columns and columns as rows of
dataframe:
(a) df.t()
(b) df.T
(c) df.transpose()
(d) Df.transpose

Ans: (b) df.T

124. Which of the following is Not True about Series and Dataframe:
(a) Both are size mutable
(b) Both can be derived from pandas
(c) Both can be reshaped into different forms
(d) Both can be created by passing data in form of list dictionaries and ndarray

Ans: (a) Both are size mutable

125. To access individual item from dataframe ‘df’ which of the following is Not correct?
(a) df.loc[2,2]
(b) df.iat[2,2]
(c) df.at[2,2]
(d) df[0,0]

Ans: (a) df.loc[2,2]

126. Aastha has given the following command to delete a column ‘pub’ from the ‘book’
dataframe .
book.drop(‘pub’)
But she is not getting the desired output , help her to select the correct statement .

a) book.drop([‘pub])
b) book.drop([‘pub’,axis=0)

c) book.drop([‘pub’,axis=1)
d) none
Ans - c) book.drop([‘pub’,axis=1)

Case Based Study


Consider the following dataframe df and answer your question .
Boys girls subject awards
Class1 24 18 5 8
Class2 20 20 5 11
Class3 16 30 5 13
Class4 24 19 6 NaN

127. What will be the output of thee command df.size


a) 4 b) 16 c) (4,4) d) 15
Ans : b) 16
128. Add a new column ‘rank’ with 1,2,3,4 to the dataframe .
a) df.[‘rank’] = [1,2,3,4]
b) df.at[‘rank’] = [1,2,3,4]
c) df.loc[‘rank’] = [1,2,3,4]
d) all true

Ans : a) df[‘rank’] = [1,2,3,4]

129. Your class teacher wants to update the value of column award of class 4 to 6 which
is currently NaN. Help him to select correct statement
a) df.at[‘class4’,’awards’, ]=6
b) df.loc[‘class4’,’awards’, ]=6
c) both are true
d) both are false

Ans: c) both are true

130. Write commands to display

Boys girls
Class1 24 18
Class2 20 20

a) print(df.iloc[1,2:1,2])
b) print(df.iloc[0,3:0,3])
c) print(df.iloc[0,2:0,2])
d) print(df.iloc[1,3:1,3])

Ans : c) print(df.iloc[0,2:0,2])
131. We can add a new r0w ‘Class 5‘ at the end of dataFrame with the values for all columns
as
a. df.at[‘class5’]=[21, 20, 6, 12]
b. df[‘class5’]=[21, 20, 6, 12]
c. df.loc[‘class5’]=[21, 20, 6, 12]
d. df.class5=[21, 20, 6, 12]
e. Both a & c
f. All 0f the above

Ans. e. Both a & c

132. Command to delete column ‘subject’ is


a. del df.subject
b. del df[‘subject’]
c. drop(df[‘subject’])
d. df.drop(‘subject’)

Ans. b. del df[‘subject’]

133. Consider the following dataframe ‘emp’

ename dept
e1 a.k om
e2 m.s ee

What will be the output of the following code you execute?


emp[‘sal’] = 2000
print(emp)

(a) ename dept sal (c) ename dept


e1 a.k om 2000 e2 m.s. ee
e2 m.s ee NaN sal 2000 2000

(b) ename dept sal (d) error


e1 a.k om 2000
e2 m.s ee 2000

Ans. (b) ename dept sal


e1 a.k om 2000
e2 m.s ee 2000
134. Sameer wants to access ‘Author’ column from ‘Book’ dataframe. Suggest him to correct
statement:

a. print(Book.Author)
b. print(Book[‘Author’])
c. Both are true
d. (a) true (b) false

Ans. d. (a) true (b) false

135. Which of the following statement is true ?

a. With iloc, both start index and end index are included in the result
b. With loc, like slices end label is excluded from result.
c. With iat, we can access individual value for a row/column label pair.
d. To access individual data from a dataframe, we can use row index with
‘<dataframe>.column[]’ in a square bracket.

Ans. d. To access individual data from a dataframe, we can use row index with
‘<dataframe>.column[]’ in a square bracket.

136. To count the total no. of rows in a dataframe we use


(a) count()
(b) len()
(c) values()
(d) All of the above
Ans. (b) len()

137. What will be the output of the given code?


df=pd.DataFrame({‘c1’:[12,34,45], ‘c2’:[31,21,44]’, ‘c3’:[74,41,20] })
print(df.index)
(a) Index([0,1,2], dtype= ‘int’)
(b) RangeIndex(start=0,stop=3,step=1)
(c) 0 1 2
(d) None of the above
Ans. (b) RangeIndex(start=0, stop=3, step=1)

138. In the following question two statements are given-


One assertion denoted by A and the other reason denoted by R.
Select the correct answer as per the given choices.

(A) For a given data frame df of shape (3,3) when we are assigning the values using the
following code
Df.column1[23,45,12,21]
Python gives error
(R) While assigning values to a column of a data frame, then the sequence containing
values must be equal to the no of rows in the data frame

(a) A is false but R is true


(b) A is true but R is false
(c) Both are true but R is not the correct explanation of A
(d) Both are true and R is the correct explanation of A
Ans. (d) Both are true and R is the correct explanation of A

139. If the shape of the passed values in the index sequence and the length of the dictionary’s
values are not same, then python gives
(a) Index error
(b) Value error
(c) Key error
(d) Runtime error
Ans. (b) Value error

140. A data frame has two axes, where axis=0 represents


(a) Row
(b) Column
(c) Index
(d) Value
Ans. (a) Row

141. To count total number of rows of dataframe ‘df’ which of the following command can be
written.
(a) len(df)
(b) df.len
(c) df.len()
(d) All are correct

Ans: (a) len(df)

142. What will the following statement display?


df.iloc[2:7,:3]
(a) Display 2nd to 7th row and first three columns.
(b) Display 3rd to 7th row and first three columns.
(c) Display 2nd to 8th row and first four columns.
(d) Display 3rd to 8th row and first four columns.

Ans: (b) Display 3rd to 7th row and first three columns.
143. Which of the following is used to merge two dataframes?
(a) Join()
(b) Merge()
(c) Extend()
(d) Append()

Ans: (d) Append

144. Consider the following code:


wk1={‘mon’:12,’tue’:14}
wk2={‘wed’:23,’thu’:21}
dftemp={‘A’,wk1,’B’:wk2}
df=pd.DataFrame(dftemp)

Write command to display indexes of df


(a) df.index()
(b) df.index
(c) df.indexes
(d) df.indexes()

Ans: (b) df.index

145. What will be output of following code?


df=pd.DataFrame(np.array([[5,3,8],[4,2,7,9]]))
print(df)
(a) 0 1 2 (c) 0 1
0 5 3 8 NaN 0 5 4
1 4 2 7 9 1 3 2
2 8 7
(b) 0 3 NaN 9
0 [5,3,8]
1 [4,2,7,9]

Ans: (b) 0
0 [5,3,8]
1 [4,2,7,9]

146. Which of the following is used to represent a dataframe as numpy array?


a). shape
b). values
c). dtypes
d). Size
Ans : b). values

147. To access the value of data using column labels we can use :
a). loc
b). <dataframe object>.<column label>
c). <dataframe object>[column label]
d). b and c
e). All

Ans : e). All

148. Consider the following dataframe df and answer your questions from 5-10.

Schools hospitals gym


Jaipur 120 30 5
Raipur 130 34 4
Nagpur 158 57 12
Kanpur 144 48 9

Find the sum of all the columns given below :

Jaipur 155
Raipur 168
Nagpur 227
Kanpur 201

a). df.sum()
b). df.sum(axis=0)
c). df.sum(axis=1)
d). df.sum

Ans : c). df.sum(axis=1)

149. Write the appropriate command to display names of all the rows.
a). df.shape
b). df.axis
c). df.labels
d). df.index

Ans : d). df.index


150. What will be the output of df.max(axis=1)?
a). Jaipur 120
Raipur 130
Nagpur 158
Kanpur 144

b). school 158


hospital 57
gym 12

Ans : a). Jaipur 120


Raipur 130
Nagpur 158
Kanpur 144
151. Consider the following dataframe df and answer your questions.
Schools hospitals gym
Jaipur 120 30 5
Raipur 130 34 4
Nagpur 158 57 12
Kanpur 144 48 9

Which of the following will return exact no.of values in each columns?
a. df.columns
b. df.count()
c. df.size()
d. df.shape()

Ans: b. df.count

152. How can we increase values of column ‘gym’ by 30%?


a. df.gym = df.gym + df,gym*3
b. df[‘gym’] = df[‘gym’] + df[‘gym’]*0.3
c. Both are true
d. Both are false

Ans: c. Both are true

153. Which of the following statement is incorrect?


a. iteritems() returns each column’s value in form of series object.
b. tail() returns bottom rows by specifying values of nos. argument.
c. Transpose of Dataframe is possible through <dataframe>.T
d. Python integer type can store NaN values.
Ans: d. Python integer type can store NaN values.

154. For given dataframe ‘df’


A B
0 15 18
1 20 25
2 40 50
3 70 44
What will be the output of the following code?
df.tail(2)
a. A B b. A B
3 70 44 2 40 50
2 40 50 3 70 44

c. A B d. None of the above


1 20 25
0 15 18
Ans: b. A B
2 40 50
3 70 44

155. Attribute used to return total no. of elements as integer of a DataFrame is


a. Size
b. Count
c. Value
d. Len
Ans: d. Len

156. Which of the following is used to fill missing values in a dataframe?

a) skipna
b) fillna
c) replacena
d) inplacena

Ans : b) fillna

157. How to rearrange the


columns of a dataframe having columns ('name', 'age', 'address', 'sal')

a) df=df.reindex(columns=['age', 'name', 'sal' ])


b) df=df[['sal', 'name', 'age']]
c) df=df[columns= ['sal', 'name', 'age']]
d) a) and b)
e) a) and c)

Ans : d). a) and b)

158. The difference between at and iat is

a) 'at' accesses a single value for a row/column pair by integer position and 'iat' accesses a
row/column pair using labels
b) 'at' accesses a single value for a row/column pair using labels and 'iat' accesses a
row/column pair by integer position
c) 'at' extracts a subset from the dataframe using row/column labels and 'iat' extracts a
subset using row/column integer position
d) 'at' extracts a subset from the dataframe using row/column integer position and 'iat'
extracts a subset using row/column labels

Ans : b) 'at' accesses a single value for a row/column pair using labels and 'iat' accesses a
row/column pair by integer position

159. To display three rows from the bottom of a dataframe, which of the following can be written

(i). df.tail(3)
(ii). df.iloc[-3:]

a) (i) is incorrect, (ii) is correct


b) (i) is correct, (ii) is incorrect
c) both are correct
d) both are incorrect

Ans : c) both are correct

160. To add a new row in a dataframe 'emp' we can write

a) emp.loc[len(df)]=[1,'raghu', 2300]
b) emp.iloc[len(df)]=[1,'raghu', 2300]
c) emp.iloc[-1]=[1,'raghu',2300]
d) emp.loc[-1]=[1,'raghu',2300]

Ans : a) emp.loc[len(df)]=[1,'raghu', 2300]


161. While creating a dataframe using 2D dictionary, which of the following is not true?
(i) Keys of all inner dictionaries should be the same
(ii) Keys of inner dictionaries make columns and keys of outer dictionaries make the indexes.

a) Both are true


b) Both are false
c) (i) True, (ii) false
d) (i) False, (ii)true

Answer: c) (i) True, (ii) false

162. Find the output of the given code-

df=pd.DataFrame(np.array([[5,3,8],[4,2,7]])
print(df.shape)

(a) (3,2)
(b) (2,3)
(c) (2,1)
(d) (1,2)

Answer: (b) (2,3)

163. In the following questions two statements are given one assertion denoted with (A) and
other reason denoted with (R). Select the correct answer as per given choices.

a. (A) is False but (R) is True


b. (A) is True but (R) is False
c. Both are True but (R) is not correct explanation of (A)
d. Both are True and (R) is correct explanation of (A)

(a) we can add a new column in existing dataframe using at or loc


( r) when we assign something to a column of dataframe, then for existing column it will
change the data value and for non existing column, it will add new column

Answer: (d.) Both are True and (R) is correct explanation of (A)

164. Which of the following is correct syntax for accessing a particular column of dataframe
(a) df.<columnname>
(b) df.[‘columnname’]
(c) df.loc[:,’columnname’]
(d) All are correct

Answer: (d) all are correct

165. Which of the following statements for creating a dataframe is valid?

(a) df=pd.dataframe(dict1)
(b) df=pd.Dataframe(dict1)
(c) df=pd.dataFrame(dict1)
(d) df=pd.DataFrame(dict1)

Answer: (d) df=pd.DataFrame(dict1)

166. What will be the output of the following code?


School={'class1':{'Rollno':1,'Name':'Amar'},
'class2':{'Rollno':2,'Name':'Sultan'}}
Df=pd.Dataframe(School)
Print(Df)

(a) Name Rollno


Class1 Amar 1
Class2 Sultan 2

(b) Rollno. Name


Class1 1. Amar
Class2. 2. Sultan

(c) Class1. Class2


Name. Amar. Sultan
Rollno. 1. 2

(d). Class1. Class2


Rollno. 1. 2
Name. Amar. Sultan

Ans:(d)

Class1. Class2
Rollno. 1. 2
Name. Amar. Sultan

167. Which of the following is not true about count () used in pandas

(i) By default count() method counts values for each column of datafrrame
(ii) df.count and df.count(axis='index') produces same result

(a) Both are true


(b) Both are false
(c) (i)true,(ii) false
(d) (i)false,(ii)true

Ans: (a) Both are true

168. When a dataframe is created using 2D dictionary,column labels are formed by:

(a) Key of outer dictionary


(b) Key of inner dictionary
(c) Value of outer dictionary
(d) Value of inner dictionary

Ans: (a) Key of inner dictionary

169. To extract the first three rows and three columns of a dataframe 'exp' which of the following
is true:

(a) exp.iloc[0:2,0:2]
(b) exp.iloc[0:3,0:3]
(c) exp.iloc[1:3,1:3]
(d) exp.iloc[1:4,1:4]

Ans:(b) exp.iloc[0:3,0:3]

170. A dataframe object can be created using:

(a) Python Dictionary


(b) Python List
(c) Pandas Series
(d) All

Ans: (d) All


171. Which of the following is missing data?
(a)NULL
(b)NaN
(c)None
(d)All of the above
Ans: (d) All of the above

172. While accessing a subset from a dataframe using loc, the end label is always included in
the result set?
(a)True
(b)False
Ans: (a)True

173. Select appropriate code to list the values of cell in 5th row in ‘item’ column
(a)df.loc[4,’item]
(b)df.loc[5,’item’]
(c)df.at[4,’item’]
(d) a and c
Ans: (d) a and c

174. What will be the shape of the given dataframe?


5 4 3 2 9
6 4 6 3 7
(a) (5,2)
(b) (2,5)
(c) (10,)
(d) (2,)
Ans: (b) (2,5)

175. Which of the following is the correct statement?


(a) Inplace argument of rename function is set to False, then original dataframe is changed
with new index/columns.
(b) del statement of dataframe can be used to delete rows
(c) When a dataframe object is created, all the columns are sorted automatically.
(d) While specifying your own index sequence in DataFrame() function, Python doesn’t care
about length of index.
Ans: c. When a dataframe object is created, all the columns are sorted automatically.

176.To access individual item from a dataframe 'df' which of the following is not correct:

a. df.at[row_index, , column_index]

b. df.iat[row_index, column_index]
C. df.<column label>[row_index]

d. df.iloc [row_index, column_index]

Ans . (a)df.at[row_index, , column_index]

177.In the following questions two statements are given one assertion denoted with (A) and
other reason denoted with (R). Select the correct answer as per given choices.

(a) the code written below

df = pd.DataFrame(np.array([[5,3,8], [4,2,7,9]]))

print(len(df))

will display dataframe as

[5,3,8]

[4,2,7,9]

(r) python create only single column in dataframe object if data passed to it is ndarray with rows
of different length.

a. (A) is False but (R) is True b. (A) is True but (R) is False

c. Both are True but (R) is not correct explanation of (A)

d. Both are True and (R) is correct explanation of (A)

Ans. (d) Both are True and (R) is correct explanation of (A)

178.Considering following dataframe 'class'

boys girls subject award


class 1 24 16 5 8
class 2 20 20 5 10
class 3 18 33 6 13
class 4 21 19 6 9
Which of the following is not correct?

a. print(class.lock girls':'subject']) b.print(class.loc ['class 1':'class 2','girls':'subject']

c. Print(class.loc[['class 1','class2'],['girls','subject']]

d. Print(class.loc['class 1','girls']

e. a and b

f. all are correct

Ans. (f) all are correct .

179.Which of the following can be used to add a new column in


existing dataframe:

a. loc

b. at

C. iloc

d. <dataframe_object>.<column_lable>

Ans. all are correct

180.Which of the following is correct syntax of using DataFrame() for defining a dataframe?

a. pandas.DataFrame(Data, index, columns, dtype, copy)


b. pandas.DataFrame(Data, index, columns, dtype)
c. pandas.DataFrame(Data, index, columns)
d. option b and c
e. all of the above .

ans. (e) all of the above .

181. Find the output of the following code :

Df=pd.Dataframe({‘soap’:pd.Series([23,45,34],[‘A’, ‘B’. ‘C’])

‘salt’: pd.Series([11,23], [‘A’, ‘B’])

‘sugar’: pd.Series([20,54], [‘A’, ‘B’])})


Print(df)

A. B.

soap salt sugar A B C D

A 23.0 11.0 NaN soap 23.0 45.0 34.0 NaN

B 45.0 23.0 NaN salt 11.0 23.0 NaN NaN

C 34.0 NaN 20.0 sugar NaN NaN 20.0 54.0

D NaN NaN 54.0

ANSWER : A

182. Which of the following statement is incorrect for adding new column ‘sal’ in
dataframe emp?

a. emp.sal[200,300]

b. emp.loc[:, ‘sal’]=[200,300]

c. emp=emp.assign(‘sal’=[200,300])

d. emp.at[:,’sal’]=[200,300]

ANSWER : (A) emp.sal[200,300]

183. Which of the following statement is not true?

a. When values are assigned to column of dataframe for non-existing column, it will ad a new
column.

b. in iloc, like slices and index/positions is excluded when gives as start: end

c. while creating a dataframe from 2D Dictionary, keys of all inner dictionaries must be same in
number or name

d. by default in drop function of dataframe object value of axis is 1 always.

ANSWER : (D) by default in drop function of dataframe object value of axis is 1 always.
184. Ritika has created one dataframe as given below:

Df=pd.DataFrame(dict1)

But she doesn’t know how to transpose dataframe, help her to do so .

a. df.T

b. df.t

c. df.Transpose

d. df.Transpose()

ANSWER : (A) df.T

185. For given dataframe ‘df’

A B

0 15 18

1 20 25

2 40 50

3 70 44

What will e the output of the following code ?

print(df[‘A’] =40)

a) A

0 15

1 20

2 40

3 70

b) A

2 40
c) A

0 False

1 Fals

186. Which of the following statement is not true?

a. When values are assigned to column of dataframe for non-existing column, it will ad a new
column.

b. in iloc, like slices and index/positions is excluded when gives as start: end

c. while creating a dataframe from 2D Dictionary, keys of all inner dictionaries must be same in
number or name

d. by default in drop function of dataframe object value of axis is 1 always.

ANSWER : (D) by default in drop function of dataframe object value of axis is 1 always.

187.Write the output of the following :


>>> import pandas as pd

>>> series1 = pd.Series([10,20,30])

>>> print(series1)
a.

Output:

0 10

1 20

2 30

dtype: int64
b.

Output:

10

20
30

dtype: int64
c.

Output:

dtype: int64
d. None of the above
Ans. a

188.How many values will be there in array1, if given code is not returning any error?
>>> series4 = pd.Series(array1, index = [“Jan”, “Feb”, “Mar”, “Apr”])

a. 1

b. 2

c. 3

d. 4

Ans. d. 4

189.When we create a series from dictionary then the keys of dictionary become
________________
a. Index of the series

b. Value of the series

c. Caption of the series

d. None of the series

Ans. a.index of the series


190. Write the output of the following :
>>> S1=pd.Series(14, index = ['a', 'b', 'c'])
>>> print(S1)
a.

a 14
b 14
c 14
dtype: int64
b.

a 14
dtype: int64
c. Error

d. None of the above


Ans. a.

2 True

3 False

d) A

0 40

1 40

2 40

3 40

ANSWER : (D )

191. Consider following dataframe ‘class’


Boys girls subject awards
class1 24 16 5 8
class2 20 20 5 10
class3 18 33 6 13
class4 21 19 6 9
Which of the following is not correct?

A. class.loc[‘class1’,:]
B. class.loc[:,’boy]
C. class.loc[‘class’]
D. class.loc[‘boy’]

Answer: (D) class.loc[‘boy’]

192 Sandesh hs written following code to create dataframe with boolean index:
df.pd.DataFrame([1,2,3],index=[true,false,true])
When executing this code he is getting key error. Suggest him for correction:

A. df=pd.DataFrame([1,2,3],index = [‘true’, ’false’, ‘true’])


B. df=pd.DataFrame([1,2,3],index = [‘True’, ’False’, ‘True’])
C. df=pd.DataFrame([1,2,3],index = [true, false, true])
D. df=pd.DataFrame([1,2,3],index = [‘0’, ‘1’, ‘0’])

Answer: (C) df=pd.DataFrame([1,2,3],index = [true, false, true])

193: Which is true

a. Pandas supports non unique index values


b. Pandas supports label based indexing
c. Pandas used range method for implicit indexing.
d. All are true

194: Which of the following is not parameter of append() method used to merge two
dataframes?

a. Axis
b. Sort
c. Verify_integrity
d. Ignore_index

Answer: (a) Axis


195: When a dataframe is created using dictionary of any sequence such as series or list,
the resulting index or labels are ________ of all indexes or labels.

a. Union
b. Intersection
c. Product
d. Sum

Answer: (a) Union

196. Find the output of:


d1={‘A’:10, ‘B’:20}
d2={‘A’:50, ‘C’:30}
d={‘i’:d1, ‘ii’:d2}
df=pd.DataFrame(d)
print(df)

a) i ii b) i ii c) A B C
A 10 50 A 10 NaN i 10 20 NaN
B 20 NaN B 50 NaN ii 20 NaN 30
C NaN 30 C NaN 30

d) A B C
i 10 50 NaN
ii 20 NaN 30

ANSWER: a

197. For a dataframe df[:]=0 will


a) Create result set with elements having data equal to 0
b) Assign 0 to all its elements
c) Display value of first row and column
d) Assign value of first row and column

ANSWER: b

198. In the following questions two statements are given- one assertion denoted with(A) and
other reason denoted with(R). Select the correct answer as per given choices.
(a) For given dataframe
Rno name class
Sec1 1 ram 12
Sec2 2 hari 11
Sec3 3 akbar 12

When executing following code:


df.drop([‘class’])

Will produce error

(b)We can give axis=1 along with indexes/labels in drop method to delete column(s).

a. (A) is false but (R) is true


b. (A) is true but (R) is false
c. Both are true but (R) is not correct explanation of (A)
d. Both are true and (R) is correct explanation of (A)

ANSWER: d

199. For given dataframe


Coachid name rank
A 1 Jack 12
B 2 Kim 3
C 3 Rajan 4
D 4 Juber 11
E 5 Hanuma 2

When Raja is trying to rename indexes using following code:


df.rename(index=[‘a’,’b’,’c’])
He is getting error. Help him to select correct command to rename columns

a. df.rename(index=[‘a’,’b,’,’c’], column={})
b. df.rename(index={‘A’:’a’,’B’:’b’,’C’:’c’})
c. df.rename(index=[‘A’=’a’,’B’=’b’,’C’=’c’])
d. df.rename(index=(‘a’,’b’,’c’))

ANSWER:b

200. Find the output of given code

d1={‘name’:[‘jail’,’veer’,’shera’], ‘code’: np.array([102,448,504]),’gender’:’m’}


df6=pd.DataFrame(d1,index=d1[‘code’])
print(df6)

a. b.
name code gender 102 448 504
102 jai 102 m name jai veer shera
448 veer 448 m code 102 448 504
504 shera 504 m gender m m m

ANSWER: a

201. In boolean Indexing we can filter data in ______ ways.

a. 1
b. 2
c. 3
d. many

ANSWER: B) 2

202. To merge two dataframes df1 and df2 with no duplicate row labels, which command
should be executed?

a. df1.append(df2, ignore_index=True)
b. df1.append(df2, ignore_index=False)
c. df1.append(df2, verify_intigrity=True)
d. df1.append(df2, verify_intigrity=True)

ANSWER: C) df1.append(df2, verify_intigrity=True)

203. For a dataframe with columns eno,ename and salary,shilpa want to add a new
column hra which will store 20% of salary.
Help her to do this.

a. df[‘hra’] = df[‘salary’]*0.2
b. df.hra = df.salary*0.2
c. df[‘hra’= df[‘salary’]*0.2]
d. None

ANSWER: A) df[‘hra’] = df[‘salary’]*0.2

204. The term used to represent row labels in a dataframe is


a. Index
b. Column
c. Row
d. Field

ANSWER: A) Index

CASE STUDY BASED MCQ


Consider the following dataframe df created by operator and answer questions
asked by admin from 5 - 10.

bcode bname rate


0 101 c++ 270
1 102 java 430
2 103 python NaN
4 104 dbms 380
5 105 mysql 320

205. If admin wants to know the rate of book which code is 103 .What command

a. df[df[‘bcode’]=103]
b. df[‘bcode’ = 103]
c. df[df[‘bcode’]==103]
d. df[‘bcode’ == 103]

ANSWER: C) df[df[‘bcode’]==103]

206. An operator colleague sugged to rename all the rows to (b1,b2,b3,b4,b5)


he wrote the following command help him to select the correct one.
a.df2.rename({0:b1,1:b2,2:b3,4:b4,5:b5})
b. df2.rebname({0:b1,1:b2,2:b3,4:b4})
c.df2.rebname({0:b1,1:b2,2:b3})
d.a.df2.rename({0=b1,1:b2,2:b3})
Ans. a

207. Admin brought a book A1 of 510 rs and ask operator to store in dataframe the
command should operator write is
a.df.at[-1]=[106,'A1',510]
b.df.loc[-1]=[106,'A1',510]
c.df.loc[lan(df)]=[106,'A1',510]
d. Both a and b
Ans. c

208. Operator found that the rate of python is missing. So he thought to fill it with 500rs
what is the command.
a.df.replacena(500)
b.df.fillna=(500)
c.df.fillna(500)
d.df.replacena=(500)
Ans. c

Assertion/Reason based MCQ

209. There are statments given below :


Select the correct answer from given choices.
(a.) A dataframe can be created with 2-D dictionary wheather it's inner dictionary have
matchhing keys or not.
(b.) NaN values see automatically filled fir values fir non matching keys of inner keys of
dictionary used in creating dataframe.
a.(A) is true (R ) is false.
b.(A) is false (R ) is true.
c. Both are true but (R ) is not a correct explanation of (A).
d.Both are true but (R ) is a correct explanation of (A).
Ans. d

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy