Python DataFrame MCQ | Class 12 IP MCQ

This post contains very important objective questions for Data handling using python pandas. It covers all concepts of python Dataframe mcq. This post is not only helpful for Informatics Practices student, but for all of them learning Python Programming and Data Science etc.

Pandas is one of the most important and useful open source Python’s library for Data Science. It is basically used for handling complex and large amount of data efficiently and easily. Pandas has derived it’s name from Panel Data System where panel represent a 3D data structure. It was developed by Wes McKinney. Basically it uses Series and Dataframe data structure for data handling.

Dataframe is 2D (Two Dimensional) data structure used to manage large and complex data in tabular format. It contains both rows and columns and hence have both row and column indexes. It is one of the most commonly used data structure similar to spreadsheet.

Python DataFrame MCQ Set-1 (Q1-Q25)

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

Show Answer

b. A dataframe is size immutable

  1. Which of the following statement for creating dataframe is valid?
    a. df = pd.dataframe(dict1)
    b. df = pd.Dataframe(dict1)
    c. df = pd.dataFrame(dict1)
    d. df = pd.DataFrame(dict1)

Show Answer

d. df = pd.DataFrame(dict1)

  1. What will be 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

Show Answer

(d)
                    Class1   Class2
          Rollno    1        2
          Name      Amar     Sultan

  1. Select the command to display both row and column index label of dataframe ‘exp’.
    a. print(exp.index)
    b. print(exp.index())
    c. print(exp.axes())
    d. print(exp.axes)

Show Answer

d. print(exp.axes)

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

Show Answer

d. All are correct

  1. Sandesh has 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’])

Show Answer

c. df = pd.DataFrame([1,2,3],index =[ True, False , True])

  1. Which of the following is correct statement?
    a. inplace argument of rename function is set to False, than 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.

Show Answer

c. When a dataframe object is created, all the columns are sorted automatically.

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

Show Answer

a. Key of outer dictionary

  1. (i) When dataframe is created with list of dictionaries, the columns are created from dictionary names.
    (ii) When dataframe is created with 2D list, column and index are labeled to 0, 1, 2… By default


    a. (i) False (ii) True  
    b. (i) True (ii) False
    c. Both are true
    d. Both are False

Show Answer

c. Both are true

  1. To access value of dataframe using column label we can use:
    a. loc
    b. <dataframe object>.<column label>
    c. Both
    d. None

Show Answer

c. Both

  1. What will be output of following code:
         import pandas as pd
         L = [so, no, go, do, to])
         df = pd.DataFrame(L)
        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

Show Answer

(b)  3  do
      4  to

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

Show Answer

a. df.at[row_index, column_index]

  1. Which of the following is not an attribute of dataframe:
    a. axes
    b. empty
    c. transpose
    d. Size

Show Answer

c. transpose

  1. To count total no of elements in a dataframe we use
    a. size
    b. len
    c. count
    d. values

Show Answer

a. size

  1. Identify the correct statement:
    a. A dataframe can only store homogeneous elements
    b. empty of dataframe counts NaN or NA values
    c. The index of dataframe can be number, letter or string.
    d. Size of dataframe returns total no of rows.

Show Answer

c. The index of dataframe can be number, letter or string

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

Show Answer

b. exp.iloc[0:3,0:3]

17. 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. print(class.loc[:,’girls’:’subject’])
b. print(class.loc[‘class1’:’class2’,’girls’:’subject’]
c. Print(class.loc[[‘class1’,’class2’],[‘girls’,’subject’]]
d. Print(class.loc[‘class’,’girls’]

Show Answer

d. Print(class.loc[‘class’,’girls’]

  1. A dataframe object can be created using:
    a. Python Dictionary
    b. Python List
    c. Panda Series
    d. All

Show Answer

d. All

  1. What will be output of 
       print(df.loc[:])


    a. Display ‘Error’
    b Display all rows
    c. Display all columns
    d. Display all rows and columns

Show Answer

d. Display all rows and columns

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

Show Answer

b. dataframe_object.column_lable

  1. A dataframe has two axes, where axes = 0 represents
    a. Row
    b. Column
    c. Index
    d. Values

Show Answer

a. Row

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

Show Answer

c. Both are true

  1. Consider the dataframe ‘emp’ given below. What will be output of following code you execute?
             emp[‘sal’] = 2000
       print(emp)
	ename	dept			 
e1	a.k.	om					
e2	m.s.	ee


(a)	ename	dept	sal			 
e1	a.k.	om	2000				
e2	m.s.	ee	NaN			
	
(b)	ename	dept	sal
e1	a.k.	om	2000
e2	m.s.	ee	2000

(c)	ename	dept					
e2	m.s.	ee	
sal	2000	2000	

(d)	Error			

Show Answer

(b)	ename	dept	sal
e1	a.k.	om	2000
e2	m.s.	ee	2000

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

Show Answer

a. len(df)

  1. What the following statement will 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 7th row and first four columns.
    d. Display 3rd to 7th row and first four columns.

Show Answer

b. Display 3rd to 7th row and first three columns.

Python DataFrame MCQ Set-2 (Q26-50)

Python 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 !!