IP Class 12 Dataframe MCQ

This post is specially created for IP Class 12 Dataframe MCQ. It covers almost all concepts in form of multiple choice questions of 1 mark. These objective type questions with answers are very important and useful for understanding Dataframe and all its concepts. We all know Dataframe is a two dimensional data structure used for storing and managing large and complex data of any type at single place. it can store heterogeneous data. it have two indexes, one for row identification and another for column identification. We can also set user defined indexes for both rows and columns of Dataframe. to use Dataframe we must include python pandas library.

IP Class 12 Dataframe MCQ Set-2 (Q26-Q50)

  1. What will be output of the following code?
    df =  pd.DataFrame([(‘ram’, 80), (‘john’, 70)])
    df.columns = [‘name’, ‘marks’]
a)	name	marks					
0	Ram	john							
1	80	70		
					
b)	0	1	name	marks
0	ram	80	NaN	NaN
1	john	70	NaN	NaN

c)	name	marks					
0	ram	80						
1	John	70		
				
d)	0	1
0	ram	80
1	john	70
2	name	marks

Show Answer

c)	name	marks					
0	ram	80						
1	John	70

  1. Which of the following statement is not correct?
    a. iteritems() returns each column’s value in form of series object.
    b. tail() returns any no of bottom rows by specifying values of nos. argument.
    c. Transpose of dataframe is available through <dataframe>. T
    d. Python integer type can store NaN values.

Show Answer

d. Python integer type can store NaN values.

  1. What will be output of the following code?
    list1 = [[10,20], [30,40], [50,60]]
    df = pd.DataFrame(list1)
    print(df)
a)  10	20	b)  0	1	c)  0	1	d)  0	1     2
0   30	40	10  30	50	0   10	20	0   10	30    50
1   50	60	20  40	0	1   30	40	1   20	40    60
				2   50	60	

Show Answer

c)	0	1	
0	10	20	
1	30	40	
2	50	60

  1. To count total no of rows in a dataframe we use
    a. count()
    b. len()
    c. values
    d. all of above

Show Answer

b. len()

  1. Which of the following is Missing data?
    a. NULL
    b. NaN
    c. None
    d. All Above

Show Answer

d. All Above

  1. 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]

Show Answer

d. df[0,0]

  1. Which of the following is not a iterative function for dataframe?
    a. iterrows()
    b. iteritems()
    c. itercolumns()
    d. none

Show Answer

c. itercolumns()

  1. For given dataframe ‘df’

                A                      B
0             15                    18
1             20                    25
2             40                    50
3             70                    44

What will be output of the following code?
df.tail(2)

a) A	B	b)  A	B	c) A	B	d) None
3  70	44	2   40	50	1  20	25		
2  40	50	3   70	44	0  15	18

Show Answer

b) A	B
2  40	50
3  70	44

  1. 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]

Show Answer

a. emp.sal[200,300]

  1. Which of the following statement is not true?
    a. When values are assigned to column of dataframe for non-existing columns, it will add a new column.
    b. in iloc, like slices end index/position is excluded when given 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.

Show Answer

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

  1. df.head() will display
    a. first five rows of dataframe
    b. all rows of a dataframe
    c. first row of dataframe
    d. nothing will be displayed

Show Answer

a. first five rows of dataframe

  1. Which of the following can not be used to add a new column in existing dataframe .
    a. loc
    b. at
    c. iloc
    d. df.<col_lable>

Show Answer

c. iloc

  1. 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

Show Answer

 b. value error

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


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

Show Answer

 c. book.drop([‘pub’],  axis = 1)

  1.  Which of the following statement is true?
    a. with iloc, both start index and end index are included in 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 square bracket.

Show Answer

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

  1. 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()

Show Answer

a. df.T

  1. Considering 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. loc[‘class1’, : ]
 b. loc[ : , ‘boy’]
 c. loc[‘class1’]
 d. loc[‘boy’]

Show Answer

d. loc[‘boy’]

  1.  to count non NaN values of dataframe, we can use
    a. size
    b. len
    c. count
    d. values

Show Answer

c. count

  1. For given dataframe ‘df’

       A      B
0     15    18
1     20    25
2     40    50
3     70    44
What will be output of the following code?
print(df[‘A’] = 40]
a)       A         b)       A        c)        A         d)        A
0       15        2        40        0       False     0        40
1       20                              1       False     1        40
2       40                              2       True      2        40
3       70                              3       False     3        40

Show Answer

d)   A
0    40
1    40
2    40
3    40

  1. (i)   a dataframe is size mutable and value mutable
    (ii)  the axis = 1 identifies the column index of dataframe

    a. both are false
    b. both are true
    c. (i) true (ii) false
    d. (i) false (ii) true

Show Answer

b. both are true

  1. 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	   d)  A    B    C
A  10	50	A   10	NaN	i  10	20   NaN   i   10   50	 NaN
B  20	NaN	B   50	20	ii 50	NaN  30	   ii  20   NaN	 30
C  NaN	30	C   NaN	30		

Show Answer

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

  1. What will be output of the following code?
    dict = {‘bookname’ : [‘C’,’C++’], ‘author’: [‘kanitkar’,’balaguruswami’]}
    df = pd.DataFrame(dict, index = [1,2])
    print(df)
a) bookname   author	      b) author         bookname				
0  C	      kanitkar	      0  kanitkar       C	
1  C++	      balaguruswami   1	 balaguruswami	C++

c) bookname   author	      d) author		bookname				
1  C	      kanitkar	      1  kanitkar	C	
2  C++	      balaguruswami   2	 balaguruswami	C++

Show Answer

c)  bookname	author
1   C++		balaguruswami
2   C		kanitkar

  1. Considering 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  
To display first two columns and two rows which of the following code are correct?

    1. class.loc[‘class1’:’class2’, ‘boys’:’girls’]
    2. class.loc[:’class2’,:’girls’]
    3. Class.iloc[0:2,0:2]
    4. Class.loc[[‘class1’,’class2’],[‘boys’,’girls’]]

 a. All are correct
 b. All are incorrect
 c. (1) and (3) are correct
 d. (3) and (4) are correct

Show Answer

a. All are correct

  1. To access the value of dataframe using row labels we can use-
    a. at
    b. loc
    c. iat
    d. iloc

Show Answer

b. loc

  1. When a dataframe is created using dictionary of any sequence such as series or list, the resulting index or row labels are ________ of all indexes or labels.
    a. Union
    b. Intersection
    c. Product
    d. Sum

Show Answer

a. Union

IP Class 12 Dataframe MCQ Set-1 (Q1-25)

IP Class 12 Dataframe MCQ Set-3 (Q51-75)

Set-4 (Q76-100)

IP Class 12 MCQ

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!