Python/Python dataframe MCQ Sample Test,Sample questions

Question:
 A _______________ is a two-dimensional labelled data structure .

1.DataFrame

2.Series

3.List

4.None of the above


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

1.Add new row in a DataFrame ‘DF1’

2.To change the data values of a row to a particular value

3.Both of the above

4.None of the above


Question:
 Display first row of dataframe ‘DF’

1.print(DF.head(1))

2.print(DF[0 : 1])

3.print(DF.iloc[0 : 1])

4.All the above


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

1.DataFrame DF has 3 rows 5 columns

2.DataFrame DF has 5 rows 3 columns

3.DataFrame DF has 3 rows 5 rowlabels

4.None of the above


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

1. 2, 4

2.4, 6

3. 4, 4

4. 2, 6


Question:
 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)

1.0

2.1

3.2

4.3


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

1.delete three columns having labels ‘Name’, ‘Class’ and ‘Rollno’

2. delete three rows having labels ‘Name’, ‘Class’ and ‘Rollno’

3.delete any three columns

4. return error


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

1.row and column label is to be changed

2. column label is to be changed

3.row label is to be changed

4.None of the above


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

1.ignore_index_val

2. ignore_index_value

3. ignore_index

4.None of the above


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

1.We are appending dF1 in dF2

2.We are appending dF2 in dF1

3.We are creating Series from DataFrame

4.None of the above


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

1.Column labels

2.Row labels

3.Both of the above

4.None of the above


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

1.values

2.Values

3.. val

4. Val


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

1.read.csv( )

2.readcsv( )

3.read_csv( )

4.Read_csv( )


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

1.rowindex

2.colindex

3.Both of the above

4.index


Question:
 Write statement to transpose dataframe DF.

1.DF.T

2.DF.transpose

3.DF.t

4.DF.T( )


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

1.sorted .

2.sorter

3.sort

4.None of the above


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

1.Only First Row

2.Only First Column

3.all

4.None of the above


Question:
DataFrame created from single Series has ____ column.

1.1

2.2

3.n (Where n is the number of elements in the Series)

4.None of the above


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

1.Label based indexing

2.Boolean based indexing

3.Both of the above

4.All the above


Question:
Display last two rows from dataframe ‘DF’

1.print(DF[-2 : -1])

2.print(DF.iloc[-2 : -1])

3.print(DF.tail(2))

4.All the above


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

1.all

2.2

3.3

4.5


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

1.first matching row from it.

2.all the matching rows from it

3. last matching row from it.

4.Return Error


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

1.First (Left Side)

2.Second

3.Last (Right Side)

4.Random


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

1.3, 3

2.3, 2

3. 2, 3

4.None of the above


Question:
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)

1.3, 3

2. 3, 4

3.3, 5

4.None of the above


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

1.Series

2. DataFrame

3.Both of the above

4.None of the above


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

1.Return error

2.Change all values of column Roll numbers to 11

3.Add new column

4.None of the above


Question:
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'

1.Return error

2.Replace the already existing values.

3.Add new column

4.None of the above


Question:
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'

1.Return error

2.Replace the already existing values.

3.Add new column

4.None of the above


Question:
Parameters of read_csv( ) function is _____

1.sep

2.Header

3.Both of the above

4.None of the above


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

1.Series

2.Dictionary

3.Both of the above

4.None of the above


Question:
The default value for sep parameter is ____

1.comma

2.semicolon

3.space

4.None of the above


Question:
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.1

2.2

3.3

4.4


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

1.1

2.2

3.3

4.4


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

1.altering the row labels

2.altering the column labels

3.altering the row and column labels (both)

4.Error


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

1.1

2.2

3.3

4.4


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

1.DataFrame

2.Series

3.List

4.Tuple


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

1.Same Output

2.Name column of DataFrame DF

3.Both of the above

4.Different Output


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

1.0

2.1

3.2

4.3


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

1.0

2.1

3.2

4.3


Question:
Transpose the DataFrame means _______

1.Row indices and column labels of the DataFrame replace each other’s position

2.Doubling the number of rows in DataFrame

3.Both of the above

4.None of the above


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

1.rloc[ ]

2. iloc[ ]

3.. loc[ ]

4.None of the above


Question:
We can create DataFrame from _____

1. Numpy arrays

2.List of Dictionaries

3.Dictionary of Lists

4.All the above


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

1.True

2.False

3.Error

4.None of the above


Question:
We can use the ______ method to merge two DataFrames

1.merge( )

2.join( )

3. append( )

4.drop( )


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

1.column

2.columns

3.index

4.None of the above


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

1.it returns an error.

2.matching row label will not change .

3.the existing row label will left as it is.

4.None of the above


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

1.Row Labels

2.Column Labels

3.Both of the above

4.None of the above


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

1.Row Labels

2.Column Labels

3.Values of rows

4.None of the above


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

1.maximum number of keys in first dictionary of the list

2. maximum number of different keys in all dictionaries of the list

3.maximum number of dictionaries in the list

4.None of the above


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

1.maximum number of keys in first dictionary of the list

2.maximum number of keys in any dictionary of the list

3. number of dictionaries in the list

4.None of the above


Question:
Which library is to be imported for creating DataFrame?

1.Python

2.DataFrame

3.Pandas

4.Random


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

1.change( )

2.rename( )

3.. replace( )

4.None of the above


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

1.delete( )

2.del( )

3. drop( )

4.None of the above


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

1.Label based indexing

2.Boolean Indexing

3.All of the above

4.None of the above


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

1.shape

2.size

3.dimension

4.values


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

1.columns

2.index

3.dtypes

4.values


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

1.Dtypes

2.DTypes

3.dtypes

4.datatypes


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

1.columns

2.index

3.dtypes

4.values


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

1.head( )

2.tail( )

3.Tail( )

4.None of the above


Question:
Which of the following function is used to create DataFrame?

1.DataFrame( )

2.NewFrame( )

3.CreateDataFrame( )

4.None of the above


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

1.DF.head( )

2.DF.header(2)

3.DF.head(2)

4.None of the above


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

1. index

2.column

3.columns

4.colindex


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

1.DF1.transpose

2.DF1.T

3.DF1.Trans

4.DF1.t


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

1. isempty

2.IsEmpty

3.empty

4.Empty


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

1.DF= DF.drop(‘R1’, axis=0)

2.DF= DF.del(‘R1’, axis=0)

3.DF= DF.drop(‘R1’, axis=0, row = ‘duplicate’)

4.None of the above


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

1.DF.Column

2.DF.column

3.DF.columns

4.DF.Columns


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

1.DF.types( )

2.DF.dtypes

3.DF.dtypes( )

4.All the above


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

1.DF.dim

2.DF.ndim

3.DF.dim( )

4.None of the above


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

1. DF.Index

2.DF.index( )

3.DF.index

4.DF.row_index


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

1.DF1 = DF1.drop(‘R1’, axis = 0)

2.DF1 = DF1.drop(‘R1’, axis = 1)

3.DF1 = DF1.del(‘R1’, axis = 0)

4.DF1 = DF1.del(‘R1’, axis = 1)


Question:
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

1.True

2.False

3.Error

4.None of the above


Question:
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

1.True

2.False

3.Error

4.None of the above


Question:
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

1.(3, 4)

2.(4, 3)

3. (3, 3)

4.All the above


Question:
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

1.9

2.12

3.6

4.None of the above


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

1.verify_integrity

2.verifyintegrity

3.verify.integrity

4.None of the above


Question:
_________ data Structure has both a row and column index.

1. List

2.Series

3.DataFrame

4.None of the above


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
  50. Python MCQ
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!