Python Tutorial: MCQ DataFrame-I

Saturday, 31 July 2021

MCQ DataFrame-I

Q1.        

What is the purpose of index attribute in dataframe:

(a) Fetch the dimension of the given dataframe

(b) Fetch the size of the given dataframe

(c) Fetch both index and column names of the given dataframe

(d) Fetch the index’s name in the dataframe

Ans: (d)

Q2.        

What is the purpose of ndim attribute in dataframe:

(a) Fetch the dimension of the given dataframe

(b) Fetch the size of the given dataframe

(c) Fetch both index and column names of the given dataframe

(d) Fetch the data type values of the items in the dataframe

Ans: (a)

Q3.        

What is the purpose of size attribute in dataframe:

(a) Fetch the dimension of the given dataframe

(b) Fetch the size of the given dataframe

(c) Fetch both index and column names of the given dataframe

(d) Fetch the data type values of the items in the dataframe

Ans : (b)

Q4.        

What is the purpose of axes attribute in dataframe:

(a) Fetch the dimension of the given dataframe

(b) Fetch the size of the given dataframe

(c) Fetch both index and column names of the given dataframe

(d) Fetch the index’s name in the dataframe

Ans : (c)

Q5.        

From the 6th  display the 3rd, 4th and 5th columns from 6th to 9th rows of a dataframe DF, you can write ______________.

(a) DF.loc[6:9,3:5]

(b) DF.loc[6:10,3:6]

(c) DF.iloc[6:10,3:6]

(d) DF.iloc[6:9,3:5]

Ans: (c)

Q6.        

To change the 5th column’s value at 3rd row as 35 in dataframe DF you can write ________.

(a) DF.loc[4,6]=35

(b) DF[3,5]=35

(c) Df.iat[4,6]=35

(d) Df.iat[3,5]=35

Ans: (d)

Q7.        

Which among the following options can be used to create a DataFrame in Pandas?

(a)    A scalar value

(b)   An ndarray

(c)    A python

(d)   All of these

Ans: (d)

Q8.        

What is the output of the following code:

import pandas as pd

resultDict={'Mohit':pd.Series([76,98,54], index=['Physics','Chemistry', 'Maths']),\

        'Priya':pd.Series([65,87,43],index=['Physics','Chemistry', 'Maths']),\

        'Deep':pd.Series([60,75,83],index=['Physics','Chemistry', 'Maths'])}

resultDF=pd.DataFrame(resultDict)

print(resultDF.T)

(a) Mohit  Priya  Deep

Physics       76     65    60

Chemistry     98     87    75

Maths         54     43    83

(b) Physics  Chemistry  Maths

Mohit       76         98     54

Priya       65         87     43

Deep        60         75     83

(c) Wrong Code

(d) None of these

Ans: (b)

Q9.        

Consider the following snippet:

import pandas as pd

resultDict={'Jyoti':pd.Series([76,98,54], index=['Physics','Chemistry', 'Maths']),\

        'Vanshi':pd.Series([65,87,43],index=['Physics','Chemistry', 'Maths']),\

        'Aviral':pd.Series([60,75,83],index=['Physics','Chemistry', 'Maths']),\

            'Ankita':pd.Series([63,78,80],index=['Physics','Chemistry', 'Maths'])}

resultDF=pd.DataFrame(resultDict)

print(resultDF.count())

(a) Jyoti     3

Vanshi    3

Aviral    3

Ankita    3

dtype: int64

(b) Physics      4

Chemistry    4

Maths        4

dtype: int64

(c) Both (a) and (b)

(d) None of these

Ans: (a)

Q10.    

Consider the following snippet:

import pandas as pd

resultDict={'Jyoti':pd.Series([76,98,54], index=['Physics','Chemistry', 'Maths']),\

        'Vanshi':pd.Series([65,87,43],index=['Physics','Chemistry', 'Maths']),\

        'Aviral':pd.Series([60,75,83],index=['Physics','Chemistry', 'Maths']),\

            'Ankita':pd.Series([63,78,80],index=['Physics','Chemistry', 'Maths'])}

resultDF=pd.DataFrame(resultDict)

print(resultDF.T.count())

(a) Jyoti     3

Vanshi    3

Aviral    3

Ankita    3

dtype: int64

(b) Physics      4

Chemistry    4

Maths        4

dtype: int64

(c) Both (a) and (b)

(d) None of these

Ans: (b)

Q11.    

Consider the following snippet:

import pandas as pd

resultDict={'Jyoti':pd.Series([76,98,54], index=['Physics','Chemistry', 'Maths']),\

        'Vanshi':pd.Series([65,87,43],index=['Physics','Chemistry', 'Maths']),\

        'Aviral':pd.Series([60,75,83],index=['Physics','Chemistry', 'Maths']),\

            'Ankita':pd.Series([63,78,80],index=['Physics','Chemistry', 'Maths'])}

resultDF=pd.DataFrame(resultDict)

##print(resultDF.T)

print(resultDF.count(axis='columns'))

(a) Jyoti     3

Vanshi    3

Aviral    3

Ankita    3

dtype: int64

(b) Physics      4

Chemistry    4

Maths        4

dtype: int64

(c) Both (a) and (b)

(d) None of these

 

Q12.    

Consider the following snippet:

import pandas as pd

resultDict={'Jyoti':pd.Series([76,98,54], index=['Physics','Chemistry', 'Maths']),\

        'Vanshi':pd.Series([65,87,43],index=['Physics','Chemistry', 'Maths']),\

        'Aviral':pd.Series([60,75,83],index=['Physics','Chemistry', 'Maths']),\

            'Ankita':pd.Series([63,78,80],index=['Physics','Chemistry', 'Maths'])}

resultDF=pd.DataFrame(resultDict)

##print(resultDF.T)

print(resultDF.count(axis=‘index’))

(a) Jyoti     3

Vanshi    3

Aviral    3

Ankita    3

dtype: int64

(b) Physics      4

Chemistry    4

Maths        4

dtype: int64

(c) Both (a) and (b)

(d) None of these

Q13.    

The axis 1 identifies a dataframe’s__________

(a)        represents rows

(b)        represents columns

(c)         represents values

(d)        represents ndim

Ans: (2)

Q14.    

The axis 0 identifies a dataframe’s__________

(a)        represents rows

(b)        represents columns

(c)         represents values

(d)        represents ndim

Ans: (a)

Q15.    

To get transpose of a dataframe DF, you can write_______

(a)        DF.T

(b)        DF.Transpose

(c)         DF.Swap

(d)        All of these

Ans: (a)

Q16.    

Consider the following snippet:

import pandas as pd

resultDict={'Jyoti':pd.Series([76,98,54], index=['Physics','Chemistry', 'Maths']),\

        'Vanshi':pd.Series([65,87,43],index=['Physics','Chemistry', 'Maths']),\

        'Aviral':pd.Series([60,75,83],index=['Physics','Chemistry', 'Maths']),\

            'Ankita':pd.Series([63,78,80],index=['Physics','Chemistry', 'Maths'])}

resultDF=pd.DataFrame(resultDict)

print(____________)

Choose the correct for fetch data types of dataframes

(a)        resultDF.dtype

(b)        resultDF.dtypes

(c)         resultdf.dtype

(d)        resultdf.dtypes

Ans: (b)

Q17.    

Study code carefully and display the IP marks in ascending order. Write the code in fill in the blank:

import pandas as pd

resultDict={'Physics':pd.Series([76,98,54]), 'Maths':pd.Series([65,87,43]),\

        'English':pd.Series([60,75,83]),'IP':pd.Series([63,78,80])}

resultDF=pd.DataFrame(resultDict)

print(resultDF)

print(_______________________))

(a)        resultDF.sort_values(by=['IP'], asc=False

(b)        resultDF.sort_values(by=['IP'], desc=True

(c)         resultDF.sort_values(by=['IP'], ascending=False

(d)        resultDF.sort_values(by=['IP'], ascending=True

 

Ans: (d)

Q18.    

Study code carefully and display the IP marks in descending order. Write the code in fill in the blank:

import pandas as pd

resultDict={'Physics':pd.Series([76,98,54]), 'Maths':pd.Series([65,87,43]),\

        'English':pd.Series([60,75,83]),'IP':pd.Series([63,78,80])}

resultDF=pd.DataFrame(resultDict)

print(resultDF)

print(_______________________))

(a)        resultDF.sort_values(by=['IP'], asc=False

(b)        resultDF.sort_values(by=['IP'], desc=True

(c)         resultDF.sort_values(by=['IP'], ascending=False

(d)        resultDF.sort_values(by=['IP'], ascending=True

Ans: (c)

Q19.    

Rename column name ‘RollNO’ of the following dataframe:

import pandas as pd

s1=[101,102,103,104,105]

df=pd.DataFrame(s1)

print(df)

Output

                    0

0                     101

1                     102

2                     103

3                     104

4                     105

(a)        Df.columns=[‘RollNo’]

(b)        Df.Columns=[‘RollNo’]

(c)         df.columns=[‘RollNo’]

(d)        df.column=[‘RollNo’]

Ans: (c)

Q20.    

Which method used to add new column

(a)        assign()

(b)        insert()

(c)         both (a) and (b)

(d)        none of these

Ans: (c)

Q21.    

Choose correct syntax Selecting/Accessing a Column

(a)        <DataFrame object>[column name]

(b)        <DataFrame object>.<column name>

(c)         Both (a) and (b)

(d)        None of these

Ans: (c)

Q22.    

Choose correct Syntax Selecting/Accessing Multiple Columns:

(a)        <DataFrame object>[[<column name>,<column name>, ……..]] 

(b)        <DataFrame object>[<column name>,<column name>, ……..]  

(c)         <DataFrame object>([<column name>,<column name>, ……..])

(d)        <DataFrame object>{[<column name>,<column name>, ……..]}    

Ans : (a)

Q23.    

Choose correct Selecting/Accessing a subset from a Dataframe using Row/Column Names

(a)        <DataFrame object>.loc[<startrow>,<endrow>,<startcolumn>,<endcolumn>]

(b)        <DataFrame object>.loc [<startrow>:<endrow>,<startcolumn>:<endcolumn>]

(c)         <DataFrame object>.loc [[<startrow>:<endrow>,<startcolumn>:<endcolumn>]]

(d)        All of these

Ans: (c)

Q24.    

import pandas as pd

SData={"name":['Taran','Vinay','Vinita','Rishabh','Ravi','Manoj'],\

       'Accounts':[54,76,98,54,76,87],'English':[89,87,54,89,43,67],\

       'Bst':[65,67,87,56,87,54]}

Sno=['Sno1','Sno2','Sno3','Sno4','Sno5','Sno6']

df=pd.DataFrame(SData,index=Sno)

print(df)

print("To Access Row")

print(____________) 

How to access Sno2 Record. Choose correct code:

(a)        df.iloc['Sno2',:]

(b)        df.loc['Sno2',:]

(c)         df.loc['no2',:]

(d)        All of these

Ans: (b)

Q25.    

Choose the correct syntax  access selective columns:

(a)        <DataFrame object>.loc[:,<start column>:<end column>]

(b)        <DataFrame object>loc[:,<start column>:<end column>]

(c)         <DataFrame object>.loc[<start column>:<end column>]

(d)        <DataFrame object>.loc[(:,<start column>:<end column>)]

Ans: (a)

Q26.    

import pandas as pd

SData={"name":['Taran','Vinay','Vinita','Rishabh','Ravi','Manoj'],\

       'Accounts':[54,76,98,54,76,87],\

       'English':[89,87,54,89,43,67],\

       'Bst':[65,67,87,56,87,54],\

       'IP':[98,76,98,56,87,99]}

Sno=['Sno1','Sno2','Sno3','Sno4','Sno5','Sno6']

df=pd.DataFrame(SData,index=Sno)

print(df)

print("To access selective columns")

print(df.loc[:,'Accounts':'IP'])

print()

print(__________________))

Suggest Aviral, how to display ‘Accounts’ and English:

(a)        df.loc[:,'Accounts':'English']

(b)        df.iloc[:,0:3]

(c)         both (a) and (b)

(d)        df.iloc(:,0:3)

Ans : (b)

Q27.    

What is the output of the following code:

import pandas as pd

SData={"name":['Taran','Vinay','Vinita','Rishabh','Ravi','Manoj'],\

       'Accounts':[54,76,98,54,76,87],'English':[89,87,54,89,43,67],\

       'Bst':[65,67,87,56,87,54], 'IP':[98,76,98,56,87,99]}

Sno=['Sno1','Sno2','Sno3','Sno4','Sno5','Sno6']

df=pd.DataFrame(SData,index=Sno)

print("To access range of columns from range of rows")

print(df.loc['Sno2':'Sno5','Accounts':'IP'])

(a)                  Accounts  English  Bst  IP

Sno2        76       87       67   76

Sno5        76       43       87   87

(b)                  Accounts    IP

Sno2        76       76

Sno3        98       98

Sno4        54       56

Sno5        76       87

(c)                   Accounts  English  Bst  IP

Sno2        76       87       67  76

Sno3        98       54       87  98

Sno4        54       89       56  56

Sno5        76       43      87  87

(d)                  Accounts    IP

Sno2        76       76

Sno5        76       87

Ans: (c)

Q28.    

Write the purpose of loc

(a)        loc is label-based, which means that you have to specify rows and columns based on their row and column labels.

(b)        loc is integer position-based, so you have to specify rows and columns by their integer position values (0-based integer position).

(c)         Option (a) is correct

(d)        Both (a) and (c)

Ans: (d)

Q29.    

>>> df.loc['Fri', :]

What is the purpose of above code

(a)                To get all columns

(b)                To set all columns

(c)                 To get all rows

(d)                To set all rows

Ans: (a)

Q30.    

>>> df.loc[['Thu', 'Fri'], 'Temperature']

What is the purpose of above code:

(a)               To get Thu, Fri columns and Temperature row

(b)               To get Thu, Fri rows and Temperature column

(c)                Both (a) and (b) are wrong statements

(d)               None of these

Ans: (b)

Q31.    

Who is the main author of Pandas?

(a)        Dennis M. Ritchie

(b)        Guido van Rossum

(c)         James Gosling

(d)        Wes McKinney

Ans: (d)

Q32.    

Choose the correct command using insert() function to add a new column in the last place (3rd place) named “Salary” from the list Sal=[1000,2000,6000] in an existing dataframe named EMP already having 2 columns.

(a)        Emp.insert(loc=3,column=”Salary”,value=Sal)

(b)        Emp.insert(loc=3,column=”Sal”,value=Salary)

(c)         Emp.insert(loc=3,columns=”Salary”,value=Sal)

(d)        None of these

Ans: (a)

Q33.    

Choose the correct source code to create dataframe with the heading (a and b) from the list given below:

[[1,2],[3,4],[5,6],[7,8]]

(a)        import pandas as pd

Df=pd.DataFrame([[1,2],[3,4]],column=['a','b'])

Df2=pd.DataFrame([[5,6],[7,8]],column=['a','b'])

Df=Df.append(Df2)

print(Df)

(b)        (b) import pandas as pd

Df=pd.DataFrame([[1,2],[3,4]],columns=['a','b'])

Df2=pd.DataFrame([[5,6],[7,8]],columns=['a','b'])

Df=Df.append(Df2)

print(Df)

(c)         import pandas as pd

Df=pd.DataFrame([[1,2],[3,4]],index=['a','b'])

Df2=pd.DataFrame([[5,6],[7,8]],index=['a','b'])

Df=Df.append(Df2)

print(Df)

(d)        Both (a) and (b)

Ans : (b)

Q34.    

Assume a dataframe df1 that contains data about climatic conditions of various cities with C1,C2,C3,C4 and C5 as indexes and give the output of question from

>>>df1.shape

(a)        (4,5)

(b)        (5,4)

(c)         (5,5)

(d)        (4,4)

Ans : (b)

 


No comments:

Post a Comment