Python Data Handling MCQ | Python Pandas MCQ

This post contains multiple choice questions for data handling using python pandas. All python data handling mcq carries 1-2 marks. These mcqs are designed based on the concept of python Dataframe data structure which is considered as 2D data structure. Dataframe 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 Data Handling MCQ Set-3

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

Show Answer

c. Both are true

  1. Look at the anatomy of dataframe and select option that represents correct terms for given numbered circle.
python data handling mcq
Dataframe Anatomy

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

Show Answer

b. 1 – axis = 1, 2 – axis = 0, 3 – Missing value

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

Show Answer

d. object

  1. Select the correct statement to change rows as columns and columns as rows of a dataframe

    a. df.T()
    b. df.T
    c. df.transpose()
    d. df.transpose

Show Answer

b. df.T

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

Show Answer

a. Both are size mutable.

  1. What will be output of given code?
    df = pd.DataFrame({‘c1’:[12,34,45],’c2’:[32,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

Show Answer

b. RangeIndex(start=0, stop=3, step=1)

  1. If shape of passed values in index sequence and length of dictionary’s values are not same, than python gives

    a. Index error
    b. Value error
    c. Key error
    d. Runtime Error

Show Answer

b. Value error

  1. A dataframe has two axes, where axes = 0 represents

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

Show Answer

a. Row

  1. Which of the following is used to merge two dataframes?

    a. Join()
    b. Merge()
    c. Extend()
    d. Append()

Show Answer

d. append().

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

Show Answer

b. df.index

  1. 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        3
0	5	3	8	NaN
1	4	2	7	9		

b.	0
0	[5,3,8]
1	[4,2,7,9]

c.	
	0	1
0	5	4
1	3	2
2	8	7
3	NaN	9

Show Answer

b.	0
0	[5,3,8]
1	[4,2,7,9]

  1. which of the following is used to represent a dataframe as numpy array?

    a. shape
    b. values
    c. dtypes
    d. size

Show Answer

b. values

  1. To access value of data using column labels we can use:

    a. loc
    b. <dataframe object>.<column label>
    c. <dataframe object>[column lable]
    d. b and c
    e. All

Show Answer

d. b and c

  1. Attribute used to return total no of elements as integer of a dataframe is

    a. Size
    b. Count
    c. Values
    d. Len

Show Answer

a. Size

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

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

Show Answer

b. fillna

  1. How to rearrange 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

Show Answer

d. a and b

  1. Difference between at and iat is

    a. ‘at’ access a single value for a row/column pair by integer position and ‘iat’ access row/column pair using labels
    b. ‘at’ access a single value for row/column pair using labels and ‘iat’ access row/column pair by integer position
    c. ‘at’ extracts subset from dataframe using row/column labels and ‘iat’ extracts subset using row/column integer position
    d. ‘at’ extracts subset from dataframe using row/column integer position and ‘iat’ extracts subset using row/column labels

Show Answer

b. ‘at’ access a single value for row/column pair using labels and ‘iat’ access row/column pair by integer position

  1. To display 3 rows from 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 correct
    c. both are correct
    d. both are incorrect

Show Answer

c. both are correct

  1. 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,’rghu’,2300]
    c. emp.iloc[-1]=[1,’raghu’,2300]
    d. emp.loc[-1]=[1,’raghu’,2300]

Show Answer

b. emp.iloc[len(df)]=[1,’rghu’,2300]

  1. While creating a dataframe using 2D dictionary, Which of the following is not true?
    (i)  Keys of all inner dictionaries should be same.
    (ii)  Keys of inner dictionaries make the 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

Show Answer

c. (i) true, (ii) false

  1. Find the output of 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)

Show Answer

b. (2,3)

  1. Which of the following is not true about count() used in pandas
    (i)   Bydefault count() method counts values for each column of dataframe
    (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

Show Answer

a.  Both are true

  1. While accessing subset from a dataframe using loc, the end label is always included in resultset.

    a. True
    b. False

Show Answer

a. True

  1. Select appropriate code to list the values of cell in 5th row and ‘item’ column

    a. df.loc[4,’item’]
    b. df.loc[5,’item’]
    c. df.at[4,’item’]
    d. a and c

Show Answer

d. a and c

Python data handling mcq Set-1 (Q1-Q25)

Python data handling mcq Set-2 (Q26-Q50)

Set-4 (Q51-Q75)

IP Class 12 MCQ

1 thought on “Python Data Handling MCQ | Python Pandas MCQ”

  1. Pingback: KVS PGT Computer Science MCQ | KVS Recruitment 2022-23 – techtipnow

Leave a Comment

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

error: Content is protected !!