MCQ On Dataframe
MCQ On Dataframe
Ans: (d)
Ans: (a)
Ans : (b)
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)
Ans: (d)
Ans: (d)
Ans: (b)
Ans: (a)
Ans: (b)
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
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
Ans: (2)
Ans: (a)
Ans: (a)
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)
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)
Ans: (c)
Ans: (c)
Ans : (a)
Ans: (c)
Ans: (b)
Ans: (a)
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()
print(__________________))
Ans : (b)
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.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)
Ans: (a)
Ans: (b)
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)
******************************