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.




2. A _______________ is a two-dimensional labelled data structure .




3. _________ data Structure has both a row and column index.




4. Which library is to be imported for creating DataFrame?




5. Which of the following function is used to create DataFrame?




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




7. We can create DataFrame from _____




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




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)




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)




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




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




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




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)




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




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




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




18. DataFrame created from single Series has ____ column.




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




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




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




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




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'




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'




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




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




45. We can use the ______ method to merge two DataFrames




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




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




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




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




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




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




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




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




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




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




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




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




58. Transpose the DataFrame means _______




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




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




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




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




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




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




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




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




67. Parameters of read_csv( ) function is _____




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




69. The default value for sep parameter is ____




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




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




72. Display first row of dataframe ‘DF’




73. Display last two rows from dataframe ‘DF’




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




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




76. Write statement to transpose dataframe DF.