Home
MCQS
Python MCQ Quiz Hub
Python dataframe MCQ
Choose a topic to test your knowledge and improve your Python skills
1. In Pandas _______________ is used to store data in multiple columns.
Series
DataFrame
Both of the above
None of the above
2. A _______________ is a two-dimensional labelled data structure .
DataFrame
Series
List
None of the above
3. _________ data Structure has both a row and column index.
List
Series
DataFrame
None of the above
4. Which library is to be imported for creating DataFrame?
Python
DataFrame
Pandas
Random
5. Which of the following function is used to create DataFrame?
DataFrame( )
NewFrame( )
CreateDataFrame( )
None of the above
6. The following code create a dataframe named ‘D1’ with _______________ columns.
1
2
3
4
7. We can create DataFrame from _____
Numpy arrays
List of Dictionaries
Dictionary of Lists
All the above
8. Which of the following is used to give user defined column index in DataFrame?
index
column
columns
colindex
9. 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)
1
2
3
4
10. 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)
0
1
2
3
11. When we create DataFrame from List of Dictionaries, then dictionary keys will become ___________
Column labels
Row labels
Both of the above
None of the above
12. When we create DataFrame from List of Dictionaries, then number of columns in DataFrame is equal to the _
maximum number of keys in first dictionary of the list
maximum number of different keys in all dictionaries of the list
maximum number of dictionaries in the list
None of the above
13. When we create DataFrame from List of Dictionaries, then number of rows in DataFrame is equal to the _______
maximum number of keys in first dictionary of the list
maximum number of keys in any dictionary of the list
number of dictionaries in the list
None of the above
14. 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)
3, 3
3, 4
3, 5
None of the above
15. When we create DataFrame from Dictionary of List then Keys becomes the ______
Row Labels
Column Labels
Both of the above
None of the above
16. When we create DataFrame from Dictionary of List then List becomes the __________
Row Labels
Column Labels
Values of rows
None of the above
17. In given code dataframe ‘D1’ has _____ rows and ______ columns.
3, 3
3, 2
2, 3
None of the above
18. DataFrame created from single Series has ____ column.
1
2
n (Where n is the number of elements in the Series)
None of the above
19. 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])
2, 4
4, 6
4, 4
2, 6
20. In DataFrame, by default new column added as the _____________ column
First (Left Side)
Second
Last (Right Side)
Random
21. We can add a new row to a DataFrame using the _____________ method
rloc[ ]
iloc[ ]
. loc[ ]
None of the above
22. D1[ : ] = 77 , will set __________ values of a Data Frame ‘D1’ to 77.
Only First Row
Only First Column
all
None of the above
23. In the following statement, if column ‘Rollno’ already exists in the DataFrame ‘D1’ then the assignment statement will _____________ D1['Rollno'] = [1,2,3] #There are only three rows in DataFrame D1'
Return error
Replace the already existing values.
Add new column
None of the above
24. In the following statement, if column ‘Rollno’ already exists in the DataFrame ‘D1’ then the assignment statement will __________ D1['Rollno'] = [1, 2] #There are only three rows in DataFrame D1'
Return error
Replace the already existing values.
Add new column
None of the above
25. In the following statement, if column ‘Rollno’ already exists in the DataFrame ‘D1’ then the assignment statement will __________ D1['Rollno'] = 11
Return error
Change all values of column Roll numbers to 11
Add new column
None of the above
26. DF1.loc[ ] method is used to ______ # DF1 is a DataFrame
Add new row in a DataFrame ‘DF1’
To change the data values of a row to a particular value
Both of the above
None of the above
27. Which method is used to delete row or column in DataFrame?
delete( )
del( )
drop( )
None of the above
28. To delete a row, the parameter axis of function drop( ) is assigned the value __
0
1
2
3
29. To delete a column, the parameter axis of function drop( ) is assigned the value ____
0
1
2
3
30. The following statement will _________ df = df.drop(['Name', 'Class', 'Rollno'], axis = 1) #df is a DataFrame object
delete three columns having labels ‘Name’, ‘Class’ and ‘Rollno’
delete three rows having labels ‘Name’, ‘Class’ and ‘Rollno’
delete any three columns
return error
31. If the DataFrame has more than one row with the same label, then DataFrame.drop( ) method will delete _____
first matching row from it.
all the matching rows from it
last matching row from it.
Return Error
32. Write the code to remove duplicate row labelled as ‘R1’ from DataFrame ‘DF1’
DF1 = DF1.drop(‘R1’, axis = 0)
DF1 = DF1.drop(‘R1’, axis = 1)
DF1 = DF1.del(‘R1’, axis = 0)
DF1 = DF1.del(‘R1’, axis = 1)
33. Which method is used to change the labels of rows and columns in DataFrame?
change( )
rename( )
. replace( )
None of the above
34. The parameter axis=’index’ of rename( ) function is used to specify that the __
row and column label is to be changed
column label is to be changed
row label is to be changed
None of the above
35. What will happen if in the rename( ) function we pass only a value for a row label that does not exist?
it returns an error.
matching row label will not change .
the existing row label will left as it is.
None of the above
36. What value should be given to axis parameter of rename function to alter column name?
column
columns
index
None of the above
37. The following statement is __________ >>> DF=DF.rename({‘Maths’:’Sub1′,‘Science’:’Sub2′}, axis=’index’) #DF is a DataFrame
altering the row labels
altering the column labels
altering the row and column labels (both)
Error
38. Write a statement to delete column labelled as ‘R1’ of DataFrame ‘DF’..
DF= DF.drop(‘R1’, axis=0)
DF= DF.del(‘R1’, axis=0)
DF= DF.drop(‘R1’, axis=0, row = ‘duplicate’)
None of the above
39. Which of the following parameter is used to specify row or column in rename function of DataFrame?
rowindex
colindex
Both of the above
index
40. Which of the following are ways of indexing to access Data elements in a DataFrame?
Label based indexing
Boolean Indexing
All of the above
None of the above
41. DataFrame.loc[ ] is an important method that is used for ____________ with DataFrames
Label based indexing
Boolean based indexing
Both of the above
All the above
42. The following statement will return the column as a _______ >>> DF.loc[: , 'Name'] #DF is a DataFrame object
DataFrame
Series
List
Tuple
43. The following two statement will return _______________ >>> DF.loc[:,'Name'] #DF is a DataFrame object >>> DF['Name'] #DF is a DataFrame object
Same Output
Name column of DataFrame DF
Both of the above
Different Output
44. The following statement will display ________ rows of DataFrame ‘DF’ print(df.loc[[True, False,True]])
1
2
3
4
45. We can use the ______ method to merge two DataFrames
merge( )
join( )
append( )
drop( )
46. We can merge/join only those DataFrames which have same number of columns
True
False
Error
None of the above
47. What we are doing in the following statement? dF1=dF1.append(dF2) #dF1 and dF2 are DataFrame object
We are appending dF1 in dF2
We are appending dF2 in dF1
We are creating Series from DataFrame
None of the above
48. ______________ parameter is used in append( ) function of DataFrame to get the column labels in sorted order.
sorted .
sorter
sort
None of the above
49. _____ parameter of append( ) method may be set to True when we want to raise an error if the row labels are duplicate.
verify_integrity
verifyintegrity
verify.integrity
None of the above
50. The ________________parameter of append() method in DataFrame may be set to True, when we do not want to use row index labels.
ignore_index_val
ignore_index_value
ignore_index
None of the above
51. The append() method of DataFrame can also be used to append ____________to a DataFrame
Series
Dictionary
Both of the above
None of the above
52. Which of the following attribute of DataFrame is used to display row labels?
columns
index
dtypes
values
53. Which of the following attribute of DataFrame is used to display column labels?
columns
index
dtypes
values
54. Which of the following attribute of DataFrame is used to display data type of each column in DataFrame?
Dtypes
DTypes
dtypes
datatypes
55. Which of the following attribute of DataFrame display all the values from DataFrame?
values
Values
. val
Val
56. Which of the following attribute of DataFrame display the dimension of DataFrame
shape
size
dimension
values
57. If the following statement return (5, 3) it means _____ >>> DF.shape #DF is a DataFrame object
DataFrame DF has 3 rows 5 columns
DataFrame DF has 5 rows 3 columns
DataFrame DF has 3 rows 5 rowlabels
None of the above
58. Transpose the DataFrame means _______
Row indices and column labels of the DataFrame replace each other’s position
Doubling the number of rows in DataFrame
Both of the above
None of the above
59. Which of the following is used to display first 2 rows of DataFrame ‘DF’?
DF.head( )
DF.header(2)
DF.head(2)
None of the above
60. Which of the following statement is Transposing the DataFrame ‘DF1’?
DF1.transpose
DF1.T
DF1.Trans
DF1.t
61. Following statement will display ___________ rows from DataFrame ‘DF1’. >>> DF1.head()
all
2
3
5
62. Which of the following function display the last ‘n’ rows from the DataFrame?
head( )
tail( )
Tail( )
None of the above
63. Which property of dataframe is used to check that dataframe is empty or not?
isempty
IsEmpty
empty
Empty
64. Write the output of the statement >>>df.shape , if df has the following structure. Name Class Rollno 0 Amit 6 1 1 Anil 7 2 2 Ravi 8 3
(3, 4)
(4, 3)
(3, 3)
All the above
65. Write the output of the statement >>>df.size , if df has the following structure: Name Class Rollno 0 Amit 6 1 1 Anil 7 2 2 Ravi 8 3
9
12
6
None of the above
66. 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
True
False
Error
None of the above
67. Parameters of read_csv( ) function is _____
sep
Header
Both of the above
None of the above
68. Which of the following function is used to load the data from the CSV file into a DataFrame?
read.csv( )
readcsv( )
read_csv( )
Read_csv( )
69. The default value for sep parameter is ____
comma
semicolon
space
None of the above
70. Write statement to display the row labels of ‘DF’.
DF.Index
DF.index( )
DF.index
DF.row_index
71. Write statement to display the column labels of DataFrame ‘DF’
DF.Column
DF.column
DF.columns
DF.Columns
72. Display first row of dataframe ‘DF’
print(DF.head(1))
print(DF[0 : 1])
print(DF.iloc[0 : 1])
All the above
73. Display last two rows from dataframe ‘DF’
print(DF[-2 : -1])
print(DF.iloc[-2 : -1])
print(DF.tail(2))
All the above
74. Write statement to display the data types of each column of dataframe ‘DF’.
DF.types( )
DF.dtypes
DF.dtypes( )
All the above
75. Write statement to display the dimension of dataframe ‘DF’.
DF.dim
DF.ndim
DF.dim( )
None of the above
76. Write statement to transpose dataframe DF.
DF.T
DF.transpose
DF.t
DF.T( )
Submit