Python MCQ Quiz Hub

Python dataframe MCQ

Choose a topic to test your knowledge and improve your Python skills

In Pandas _______________ is used to store data in multiple columns.





✅ Correct Answer: 2

A _______________ is a two-dimensional labelled data structure .





✅ Correct Answer: 1

_________ data Structure has both a row and column index.





✅ Correct Answer: 3

Which library is to be imported for creating DataFrame?





✅ Correct Answer: 3

Which of the following function is used to create DataFrame?





✅ Correct Answer: 1

The following code create a dataframe named ‘D1’ with _______________ columns.





✅ Correct Answer: 1

We can create DataFrame from _____





✅ Correct Answer: 4

Which of the following is used to give user defined column index in DataFrame?





✅ Correct Answer: 3

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)





✅ Correct Answer: 3

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)





✅ Correct Answer: 2

When we create DataFrame from List of Dictionaries, then dictionary keys will become ___________





✅ Correct Answer: 1

When we create DataFrame from List of Dictionaries, then number of columns in DataFrame is equal to the _





✅ Correct Answer: 2

When we create DataFrame from List of Dictionaries, then number of rows in DataFrame is equal to the _______





✅ Correct Answer: 3

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)





✅ Correct Answer: 3

When we create DataFrame from Dictionary of List then Keys becomes the ______





✅ Correct Answer: 2

When we create DataFrame from Dictionary of List then List becomes the __________





✅ Correct Answer: 3

In given code dataframe ‘D1’ has _____ rows and ______ columns.





✅ Correct Answer: 2

DataFrame created from single Series has ____ column.





✅ Correct Answer: 1

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])





✅ Correct Answer: 4

In DataFrame, by default new column added as the _____________ column





✅ Correct Answer: 3

We can add a new row to a DataFrame using the _____________ method





✅ Correct Answer: 3

D1[ : ] = 77 , will set __________ values of a Data Frame ‘D1’ to 77.





✅ Correct Answer: 3

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'





✅ Correct Answer: 2

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'





✅ Correct Answer: 1

In the following statement, if column ‘Rollno’ already exists in the DataFrame ‘D1’ then the assignment statement will __________ D1['Rollno'] = 11





✅ Correct Answer: 2

DF1.loc[ ] method is used to ______ # DF1 is a DataFrame





✅ Correct Answer: 3

Which method is used to delete row or column in DataFrame?





✅ Correct Answer: 3

To delete a row, the parameter axis of function drop( ) is assigned the value __





✅ Correct Answer: 1

To delete a column, the parameter axis of function drop( ) is assigned the value ____





✅ Correct Answer: 2

The following statement will _________ df = df.drop(['Name', 'Class', 'Rollno'], axis = 1) #df is a DataFrame object





✅ Correct Answer: 1

If the DataFrame has more than one row with the same label, then DataFrame.drop( ) method will delete _____





✅ Correct Answer: 1

Write the code to remove duplicate row labelled as ‘R1’ from DataFrame ‘DF1’





✅ Correct Answer: 1

Which method is used to change the labels of rows and columns in DataFrame?





✅ Correct Answer: 2

The parameter axis=’index’ of rename( ) function is used to specify that the __





✅ Correct Answer: 3

What will happen if in the rename( ) function we pass only a value for a row label that does not exist?





✅ Correct Answer: 3

What value should be given to axis parameter of rename function to alter column name?





✅ Correct Answer: 1

The following statement is __________ >>> DF=DF.rename({‘Maths’:’Sub1′,‘Science’:’Sub2′}, axis=’index’) #DF is a DataFrame





✅ Correct Answer: 1

Write a statement to delete column labelled as ‘R1’ of DataFrame ‘DF’..





✅ Correct Answer: 4

Which of the following parameter is used to specify row or column in rename function of DataFrame?





✅ Correct Answer: 4

Which of the following are ways of indexing to access Data elements in a DataFrame?





✅ Correct Answer: 2

DataFrame.loc[ ] is an important method that is used for ____________ with DataFrames





✅ Correct Answer: 1

The following statement will return the column as a _______ >>> DF.loc[: , 'Name'] #DF is a DataFrame object





✅ Correct Answer: 2

The following two statement will return _______________ >>> DF.loc[:,'Name'] #DF is a DataFrame object >>> DF['Name'] #DF is a DataFrame object





✅ Correct Answer: 3

The following statement will display ________ rows of DataFrame ‘DF’ print(df.loc[[True, False,True]])





✅ Correct Answer: 2

We can use the ______ method to merge two DataFrames





✅ Correct Answer: 3

We can merge/join only those DataFrames which have same number of columns





✅ Correct Answer: 2

What we are doing in the following statement? dF1=dF1.append(dF2) #dF1 and dF2 are DataFrame object





✅ Correct Answer: 2

______________ parameter is used in append( ) function of DataFrame to get the column labels in sorted order.





✅ Correct Answer: 3

_____ parameter of append( ) method may be set to True when we want to raise an error if the row labels are duplicate.





✅ Correct Answer: 1

The ________________parameter of append() method in DataFrame may be set to True, when we do not want to use row index labels.





✅ Correct Answer: 3

The append() method of DataFrame can also be used to append ____________to a DataFrame





✅ Correct Answer: 3

Which of the following attribute of DataFrame is used to display row labels?





✅ Correct Answer: 2

Which of the following attribute of DataFrame is used to display column labels?





✅ Correct Answer: 1

Which of the following attribute of DataFrame is used to display data type of each column in DataFrame?





✅ Correct Answer: 3

Which of the following attribute of DataFrame display all the values from DataFrame?





✅ Correct Answer: 1

Which of the following attribute of DataFrame display the dimension of DataFrame





✅ Correct Answer: 1

If the following statement return (5, 3) it means _____ >>> DF.shape #DF is a DataFrame object





✅ Correct Answer: 2

Transpose the DataFrame means _______





✅ Correct Answer: 1

Which of the following is used to display first 2 rows of DataFrame ‘DF’?





✅ Correct Answer: 3

Which of the following statement is Transposing the DataFrame ‘DF1’?





✅ Correct Answer: 2

Following statement will display ___________ rows from DataFrame ‘DF1’. >>> DF1.head()





✅ Correct Answer: 4

Which of the following function display the last ‘n’ rows from the DataFrame?





✅ Correct Answer: 2

Which property of dataframe is used to check that dataframe is empty or not?





✅ Correct Answer: 3

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





✅ Correct Answer: 3

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





✅ Correct Answer: 1

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





✅ Correct Answer: 2

Parameters of read_csv( ) function is _____





✅ Correct Answer: 3

Which of the following function is used to load the data from the CSV file into a DataFrame?





✅ Correct Answer: 3

The default value for sep parameter is ____





✅ Correct Answer: 3

Write statement to display the row labels of ‘DF’.





✅ Correct Answer: 3

Write statement to display the column labels of DataFrame ‘DF’





✅ Correct Answer: 3

Display first row of dataframe ‘DF’





✅ Correct Answer: 4

Display last two rows from dataframe ‘DF’





✅ Correct Answer: 3

Write statement to display the data types of each column of dataframe ‘DF’.





✅ Correct Answer: 2

Write statement to display the dimension of dataframe ‘DF’.





✅ Correct Answer: 2

Write statement to transpose dataframe DF.





✅ Correct Answer: 1