100 Important Python Dataframe MCQ Class 12 IP
100 Important Python Dataframe MCQ Class 12 IP
100 Important Python Dataframe MCQ Class 12 IP
Q3. _____________ data Structure has both a row and column index.
a. List
b. Series
c. DataFrame
d. None of the above
a. Python
b. DataFrame
c. Pandas
d. Random
a. DataFrame( )
b. NewFrame( )
c. CreateDataFrame( )
d. None of the Above
Q6. The following code create a dataframe named ‘D1’ with _______________ columns.
import pandas as pd
D1 = pd.DataFrame([1,2,3] )
a. 1
b. 2
c. 3
d. 4
Q7. We can create DataFrame from _____
a. Numpy arrays
b. List of Dictionaries
c. Dictionary of Lists
d. All of the above
Q8. Which of the following is used to give user defined column index in DataFrame?
a. index
b. column
c. columns
d. colindex
Q9. The following code create a dataframe named ‘D1’ with ___________ columns.
import pandas as pd
LoD = [{‘a’:10, ‘b’:20}, {‘a’:5, ‘b’:10, ‘c’:20}]
D1 = pd.DataFrame(LoD)
a. 1
b. 2
c. 3
d. 4
Q10. The following code create a dataframe named ‘D1’ with ______ rows.
import pandas as pd
LoD = [{'a':10, 'b':20}, {'a':5, 'b':10, 'c':20}]
D1 = pd.DataFrame(LoD)
a. 0
b. 1
c. 2
d. 3
Q11. When we create DataFrame from List of Dictionaries, then dictionary keys will
become ____________
a. Column labels
b. Row labels
c. Both of the above
d. None of the above
Q12. When we create DataFrame from List of Dictionaries, then number of columns in
DataFrame is equal to the _______
a. maximum number of keys in first dictionary of the list
b. maximum number of different keys in all dictionaries of the list
c. maximum number of dictionaries in the list
d. None of the above
Q13. When we create DataFrame from List of Dictionaries, then number of rows in
DataFrame is equal to the ____________
a. maximum number of keys in first dictionary of the list
b. maximum number of keys in any dictionary of the list
c. number of dictionaries in the list
d. None of the above
Q14. In given code dataframe ‘D1’ has ________ rows and _______ columns.
import pandas as pd
LoD = [{‘a’:10, ‘b’:20}, {‘a’:5, ‘b’:10, ‘c’:20},{‘a’:7, ‘d’:10, ‘e’:20}]
D1 = pd.DataFrame(LoD)
a. 3, 3
b. 3, 4
c. 3, 5
d. None of the above
Q15. When we create DataFrame from Dictionary of List then Keys becomes
the _____________
a. Row Labels
b. Column Labels
c. Both of the above
d. None of the above
Q16. When we create DataFrame from Dictionary of List then List becomes
the ________________
a. Row Labels
b. Column Labels
c. Values of rows
d. None of the above
Q17. In given code dataframe ‘D1’ has _____ rows and ______ columns.
import pandas as pd
LoD = {“Name” : [“Amit”, “Anil”,”Ravi”], “RollNo” : [1,2,3]}
D1 = pd.DataFrame(LoD)
a. 3, 3
b. 3, 2
c. 2, 3
d. None of the above
a. True
b. False
Q20. In given code dataframe ‘D1’ has _____ rows and _____ columns.
import pandas as pd
S1 = pd.Series([1, 2, 3, 4], index = ['a', 'b','c','d'])
S2 = pd.Series([11, 22, 33, 44], index = ['a', 'bb','c','dd'])
D1 = pd.DataFrame([S1,S2])
a. 2, 4
b. 4, 6
c. 4, 4
d. 2, 6
Q22. We can add a new row to a DataFrame using the _____________ method
a. rloc[ ]
b. iloc[ ]
c. loc[ ]
d. None of the above
Q23. D1[ : ] = 77 , will set __________ values of a Data Frame ‘D1’ to 77.
a. Only First Row
b. Only First Column
c. All
d. None of the above
Q24. In the following statement, if column ‘Rollno’ already exists in the DataFrame ‘D1’
then the assignment statement will _____________
Q25. In the following statement, if column ‘Rollno’ already exists in the DataFrame ‘D1’
then the assignment statement will __________
Q26. In the following statement, if column ‘Rollno’ already exists in the DataFrame ‘D1’
then the assignment statement will __________
D1['Rollno'] = 11
a. Return error
b. Change all values of column Roll numbers to 11
c. Add new column
d. None of the above
a. delete( )
b. del( )
c. drop( )
d. None of the above
Q29. To delete a row, the parameter axis of function drop( ) is assigned the
value ______________
a. 0
b. 1
c. 2
d. 3
Q30. To delete a column, the parameter axis of function drop( ) is assigned the
value _____________
a. 0
b. 1
c. 2
d. 3
Q32. If the DataFrame has more than one row with the same label, then DataFrame.drop( )
method will delete _____
a. first matching row from it.
b. all the matching rows from it
c. last matching row from it.
d. Return Error
Q33. Write the code to remove duplicate row labelled as ‘R1’ from DataFrame ‘DF1’
a. DF1 = DF1.drop(‘R1’, axis = 0)
b. DF1 = DF1.drop(‘R1’, axis = 1)
c. DF1 = DF1.del(‘R1’, axis = 0)
d. DF1 = DF1.del(‘R1’, axis = 1)
Q34. Which method is used to change the labels of rows and columns in DataFrame?
a. change( )
b. rename( )
c. replace( )
d. None of the above
Q35. The parameter axis=’index’ of rename( ) function is used to specify that the ________
a. row and column label is to be changed
b. column label is to be changed
c. row label is to be changed
d. None of the above
Q36. What will happen if in the rename( ) function we pass only a value for a row label that
does not exist?
a. it returns an error.
b. matching row label will not change .
c. the existing row label will left as it is.
d. None of the above
Q37. What value should be given to axis parameter of rename function to alter column name?
a. column
b. columns
c. index
d. None of the above
Q39. Q39. Write a statement to delete column labelled as ‘R1’ of DataFrame ‘DF’..
Q40. Which of the following parameter is used to specify row or column in rename function
of DataFrame?
a. rowindex
b. colindex
c. Both of the above
d. index
Q41. Which of the following are ways of indexing to access Data elements in a DataFrame?
Q45. The following statement will display ________ rows of DataFrame ‘DF’
print(df.loc[[True, False,True]])
a. 1
b. 2
c. 3
d. 4
Q47. We can merge/join only those DataFrames which have same number of columns.(T/F)
a. True
b. False
Q50. ________ parameter of append( ) method may be set to True when we want to raise an
error if the row labels are duplicate.
a. verify_integrity
b. verifyintegrity
c. verify.integrity
d. None of the above
a. ignore_index_val
b. ignore_index_value
c. ignore_index
d. None of the above
Q52. The append() method of DataFrame can also be used to append ____________to a
DataFrame
a. Series
b. Dictionary
c. Both of the above
d. None of the above
Q53. Which of the following attribute of DataFrame is used to display row labels?
a. columns
b. index
c. dtypes
d. values
Q54. Which of the following attribute of DataFrame is used to display column labels?
a. columns
b. index
c. dtypes
d. values
Q55. Which of the following attribute of DataFrame is used to display data type of each
column in DataFrame?
a. Dtypes
b. DTypes
c. dtypes
d. datatypes
Q56. Which of the following attribute of DataFrame display all the values from DataFrame?
a. values
b. Values
c. val
d. Val
Q57. Which of the following attribute of DataFrame display the dimension of DataFrame
a. shape
b. size
c. dimension
d. values
Q60. Which of the following is used to display first 2 rows of DataFrame ‘DF’?
a. DF.head( )
b. DF.header(2)
c. DF.head(2)
d. None of the above
Q62. Following statement will display ___________ rows from DataFrame ‘DF1’.
>>> DF1.head()
a. All
b. 2
c. 3
d. 5
Q63. Which of the following function display the last ‘n’ rows from the DataFrame?
a. head( )
b. tail( )
c. Tail( )
d. None of the above
Q64. Which property of dataframe is used to check that dataframe is empty or not?
a. isempty
b. IsEmpty
c. empty
d. Empty
Q65. Write the output of the statement >>>df.shape , if df has the following structure.
Q66. Write the output of the statement >>>df.size , if df has the following structure:
Q67. Write the output of the statement >>>df.empty , if df has the following structure:
Name Class Rollno
0 Amit 6 1
1 Anil 7 2
2 Ravi 8 3
a. True
b. False
c. Yes
d. None of the above
Q69. Which of the following function is used to load the data from the CSV file into a
DataFrame?
a. read.csv( )
b. readcsv( )
c. read_csv( )
d. Read_csv( )
a. DF.Index
b. DF.index( )
c. DF.index
d. DF.row_index
a. DF.Column
b. DF.column
c. DF.columns
d. DF.Columns
a. print(DF.head(1))
b. print(DF[0 : 1])
c. print(DF.iloc[0 : 1])
d. All of the above
Q74. Display last two rows from dataframe ‘DF’
a. print(DF[-2 : -1])
b. print(DF.iloc[-2 : -1])
c. print(DF.tail(2))
d. All of the above
Q75. Write statement to display the data types of each column of dataframe ‘DF’.
a. DF.types( )
b. DF.dtypes
c. DF.dtypes( )
d. None of the above
a. DF.dim
b. DF.ndim
c. DF.dim( )
d. None of the above
a. DF.T
b. DF.transpose
c. DF.t
d. DF.T( )
a. DF[DF.columns[ 0 : 2 ] ]
b. DF.columns[ 0 : 2 ]
c. Both of the above
d. None of the above
a. DF.Shape
b. DF.shape
c. DF.shapes
d. DF.Shapes
a. DF.Empty
b. DF.empty( )
c. DF.empty
d. None of the above
Consider the DataFrame ‘DF’ given below and answer the questions from Q81 to Q90.
Following DataFrame ‘DF’ containing
year wise sales figures for five sales persons
a. DF.append(DF2)
b. DF2.append(DF)
c. DF2.update(DF)
d. None of the above
Q82. Write a statement to display the sales made by all sales persons in the year 2017.
a. print(DF.loc[: , 2017])
b. print(DF[2017])
c. Both of the above
d. None of the above
Q83. Write a statement to add new column for another year ‘2018’ with values 55000, 65000,
75000, 85000, 95000
Q84. Write a statement to add new row for ‘Raman’ with values 55000, 66000, 77000, 88000
Q85. Raman was caught in the case of cheating so his Boss decided to set his sales of all
years to 0(Zero). Help him to write the code for same.
a. DF.loc[‘Raman’] = {0}
b. DF.loc[‘Raman’] = [0]
c. DF.loc[‘Raman’] = 0
d. All of the above
a. print(DF.drop(‘Shruti’,axis=0))
b. print(DF.drop(‘Shruti’))
c. both of the above
d. none of the above
a. print(DF.drop(2017,axis=0))
b. print(DF.drop(2017,axis=1))
c. print(DF.drop(‘2017’,axis=1))
d. All of the above
Q88. Write a statement to delete two columns having column label as 2017 and 2016
Q89. Replace the row label ‘Ankit’ with ‘Ankita’ in dataframe ‘DF’
a. DF.Rename({‘Ankit’ : ‘Ankita’})
b. DF.rename({‘Ankit’ : ‘Ankita’})
c. DF.repalce({‘Ankit’:’Ankita’})
d. None of the above
Consider the DataFrame ‘DF’ given below and answer the questions from Q91 to Q100.
Following DataFrame ‘DF’ containing marks of five students in three subjects.
Science 85 82 65 60 90
Maths 90 95 85 80 75
English 80 85 75 70 60
Python DataFrame
Q91. Display the marks of Harry in Maths Subject.
a. print(DF.loc[‘Maths’, ‘Harry’])
b. print(DF.Loc[‘Maths’, ‘Harry’])
c. print(DF.loc(‘Maths’, ‘Harry’))
d. None of the above
a. print(DF.loc[‘Maths’ : ‘Science’])
b. print(DF.loc[‘Science’ : ‘Maths’])
c. Both of the above
d. None of the above
Q95. Write a statement to check that in which subject kiran scored more than 90.
a. DF.ren({“Maths” : “Mathematics”})
b. DF.Rename({“Maths”:”Mathematics”})
c. DF.rename({“Maths”:”Mathematics”})
d. DF.replace({“Maths”:”Mathematics”})
Q98. Write a statement to increase five marks of all students in all subjects.
Q99. Write a statement to add new column labelled ‘Ruby’ with values 85, 75, 79.