Skip to content

Python Objective Test

CLASS 12th PYTHON

TEST

MCQs - Data Handling: Pandas and Pyplot

Multiple Choice Questions

UNIT I: DATA HANDLING - PANDAS AND PYPLOT

1. To create an empty Series object, you can use:

(a) pd.Series(empty)
(b) pd.Series(np.NaN)
(c) pd.Series()
(d) all of these

2. To specify datatype int16 for a Series object, you can write:

(a) pd.Series(data = array, dtype = int16)
(b) pd.Series(data = array, dtype = numpy.int16)
(c) pd.Series(data = array.dtype = pandas.int16)
(d) all of the above

3. To get the number of dimensions of a Series object, ______ attribute is displayed.

(a) index
(b) size
(c) itemsize
(d) ndim

4. To get the size of the datatype of the items in Series object, you can display ______ attribute.

(a) index
(b) size
(c) itemsize
(d) ndim

5. To get the number of elements in a Series object, ______ attribute may be used.

(a) index
(b) size
(c) itemsize
(d) ndim

6. To get the number of bytes of the Series data, ______ attribute is displayed.

(a) hasnans
(b) nbytes
(c) ndim
(d) dtype

7. To check if the Series object contains NaN values, ______ attribute is displayed.

(a) hasnans
(b) nbytes
(c) ndim
(d) dtype

8. To display third element of a Series object S, you will write ______.

(a) S[:3]
(b) S[2]
(c) S[3]
(d) S[:2]

9. To display first three elements of a Series object S, you may write ______.

(a) S[:3]
(b) S[3]
(c) S[3rd]
(d) all of these

10. To display last five rows of a Series object S, you may write ______.

(a) head()
(b) head(5)
(c) tail()
(d) tail(5)

11. ______ Pandas object cannot grow in size.

(a) Dataframe
(b) Series
(c) Panel
(d) None of these

12. Given a Pandas series called Sequences, the command which will display the first 4 rows is ______.

(a) print(Sequences.head(4))
(b) print(Sequences.Head(4))
(c) print(Sequences.heads(4))
(d) print(Sequences.Heads(4))

13. If a Dataframe is created using a 2D dictionary, then the indexes/row labels are formed from ______.

(a) dictionary’s values
(b) inner dictionary’s keys
(c) outer dictionary’s keys
(d) none of these

14. If a dataframe is created using a 2D dictionary, then the column labels are formed from ______.

(a) dictionary’s values
(b) inner dictionary’s keys
(c) outer dictionary’s keys
(d) none of these

15. The axis 0 identifies a dataframe’s ______.

(a) rows
(b) columns
(c) values
(d) datatype

16. The axis 1 identifies a dataframe’s ______.

(a) rows
(b) columns
(c) values
(d) datatype

17. To get the number of elements in a dataframe, ______ attribute may be used.

(a) size
(b) shape
(c) values
(d) ndim

18. To get a number representing number of axes in a dataframe, ______ attribute may be used.

(a) size
(b) shape
(c) values
(d) ndim

1. To create an empty Series object

✅ Correct Answer: <u><b>(c) pd.Series()</b></u>

Explanation:
pd.Series() creates an empty Series.

  • (a) pd.Series(empty) → invalid unless empty is defined.

  • (b) pd.Series(np.NaN) → creates a Series with NaN value, not empty.

  • (d) Incorrect because only (c) is valid for empty Series.


2. To specify datatype int16 for a Series

✅ Correct Answer: <u><b>(b) pd.Series(data = array, dtype = numpy.int16)</b></u>

Explanation:
The correct way to define dtype is using NumPy datatype like numpy.int16.

  • (a) int16 alone is undefined unless imported.

  • (c) Syntax is incorrect.

  • (d) Incorrect because only (b) is valid syntax.


3. Number of dimensions of a Series

✅ Correct Answer: <u><b>(d) ndim</b></u>

Explanation:
ndim returns number of dimensions.
A Series is 1-dimensional → S.ndim returns 1.


4. Size of datatype of items in Series

✅ Correct Answer: <u><b>(c) itemsize</b></u>

Explanation:
itemsize returns the size (in bytes) of each element.


5. Number of elements in a Series

✅ Correct Answer: <u><b>(b) size</b></u>

Explanation:
size returns total number of elements in the Series.


6. Number of bytes of Series data

✅ Correct Answer: <u><b>(b) nbytes</b></u>

Explanation:
nbytes gives total memory consumed by data in bytes.


7. To check if Series contains NaN

✅ Correct Answer: <u><b>(a) hasnans</b></u>

Explanation:
hasnans returns True if NaN values are present.


8. To display third element of Series S

✅ Correct Answer: <u><b>(b) S[2]</b></u>

Explanation:
Indexing starts from 0.
Third element → index 2.


9. To display first three elements

✅ Correct Answer: <u><b>(a) S[:3]</b></u>

Explanation:
Slice notation → S[:3] returns elements 0,1,2.


10. To display last five rows

✅ Correct Answer: <u><b>(d) tail(5)</b></u>

Explanation:
tail(5) returns last 5 rows.
head() returns first rows.


11. Pandas object cannot grow in size

✅ Correct Answer: <u><b>(c) Panel</b></u>

Explanation:
Panel (3D structure, now deprecated) had fixed dimensions and cannot grow dynamically like DataFrame or Series.


12. Display first 4 rows

✅ Correct Answer: <u><b>(a) print(Sequences.head(4))</b></u>

Explanation:
head(4) returns first 4 rows.
Python is case-sensitive → Head(), heads() invalid.


13. DataFrame created using 2D dictionary – row labels

✅ Correct Answer: <u><b>(c) outer dictionary’s keys</b></u>

Explanation:
In a dictionary of dictionaries:
Outer keys → row labels
Inner keys → column labels


14. DataFrame created using 2D dictionary – column labels

✅ Correct Answer: <u><b>(b) inner dictionary’s keys</b></u>

Explanation:
Inner dictionary keys become column names.


15. Axis 0 identifies

✅ Correct Answer: <u><b>(a) rows</b></u>

Explanation:
Axis 0 → Row-wise operations.


16. Axis 1 identifies

✅ Correct Answer: <u><b>(b) columns</b></u>

Explanation:
Axis 1 → Column-wise operations.


17. Number of elements in a DataFrame

✅ Correct Answer: <u><b>(a) size</b></u>

Explanation:
size = rows × columns.


18. Number of axes in DataFrame

✅ Correct Answer: <u><b>(d) ndim</b></u>

Explanation:
ndim returns number of axes.
DataFrame is 2D → ndim = 2.


✅ Final Answer Key (Quick View)

  1. (c)

  2. (b)

  3. (d)

  4. (c)

  5. (b)

  6. (b)

  7. (a)

  8. (b)

  9. (a)

  10. (d)

  11. (c)

  12. (a)

  13. (c)

  14. (b)

  15. (a)

  16. (b)

  17. (a)

  18. (d)

MCQs - Data Handling: Pandas and Pyplot (Page 5)

Multiple Choice Questions

UNIT I: DATA HANDLING - PANDAS AND PYPLOT

Page 5

1. To get the transpose of a dataframe D1, you can write ______.

(a) D1.T
(b) D1.Transpose
(c) D1.Swap
(d) All of these

2. To extract row/column from a dataframe, ______ function may be used.

(a) row()
(b) column()
(c) loc()
(d) all of these

3. To display the 3rd, 4th and 5th columns from the 6th to 9th rows of a dataframe DF, you can write _____.

(a) DF.loc[6:9, 3:5]
(b) DF.loc[6:10, 3:6]
(c) DF.iloc[6:10, 3:6]
(d) DF.iloc[6:9, 3:5]

4. To change the 5th column’s value at 3rd row as 35 in dataframe DF, you can write ______.

(a) DF[4, 6] = 35
(b) DF[3, 5] = 35
(c) DF.iat[4, 6] = 35
(d) DF.iat[3, 5] = 35

5. Which among the following options can be used to create a DataFrame in Pandas?

(a) A scalar value
(b) An ndarray
(c) A python dict
(d) All of these

6. Identify the correct statement:

(a) Dataframes can change their size.
(b) Series act in a way similar to that of an array.
(c) Both (a) and (b)
(d) None of the above

7. To delete a column from a DataFrame, you may use ______ statement.

(a) remove
(b) del
(c) drop
(d) cancel

8. To delete a row from a DataFrame, you may use ______ statement.

(a) remove
(b) del
(c) drop
(d) cancel

9. To iterate over horizontal subsets of dataframe, ______ function may be used.

(a) iterate()
(b) iterrows()
(c) itercols()
(d) iteritems()

10. To iterate over vertical subsets of a dataframe, ______ function may be used.

(a) iterate()
(b) iterrows()
(c) itercols()
(d) iteritems()

11. To add two dataframes’ values, ______ function may be used.

(a) plus
(b) rplus
(c) add
(d) radd

12. To subtract the values of two dataframes, ______ function may be used.

(a) sub
(b) difference
(c) minus
(d) rsub

13. To divide the values of two dataframes, ______ function may be used.

(a) divide
(b) div
(c) rdiv
(d) division

14. Which of the following two functions will produce the same result?

(a) add
(b) radd
(c) sub
(d) rsub

15. To get the 3 bottommost rows from a dataframe, you may use ______ function.

(a) bottom
(b) bottom(3)
(c) tail()
(d) tail(3)

16. Which of the following arguments lets you specify index labels of dataframe through DataFrame()?

(a) index
(b) columns
(c) label
(d) all of these

17. To get top 5 rows of a dataframe, you may use ______ function.

(a) head()
(b) head(5)
(c) top()
(d) top(5)

18. Which of the following can be used to specify data for creating a DataFrame?

(a) Series
(b) DataFrame
(c) Structured ndarray
(d) All of these

19. All Pandas’ data structures are ______ mutable but not always ______ mutable.

(a) size, value
(b) semantic, size
(c) value, size
(d) none of these

20. Which of the following statement will import Pandas library?

(a) import pandas as pd
(b) import panda as py
(c) import pandas as py
(d) All of these

21. What will be the output for the following code?

import pandas as pd
s = pd.Series([1,2,3,4,5], index = ['a','b','c','d','e'])
print(s['a'])
(a) 1
(b) 2
(c) 3
(d) 4

22. What will be the output for the following code?

import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(2))
print(s.size)
(a) 0
(b) 1
(c) 2
(d) 3

23. What will be the output for the following code?

import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(4))
print(s.ndim)
(a) 0
(b) 1
(c) 2
(d) 3

24. What is the purpose of using ndim attribute?

(a) It returns the number of elements in the given data structure.
(b) It returns the Series object in the form of an ndarray.
(c) It returns a list of the indexes / labels.
(d) It returns the number of dimensions of the given data structure.

25. PyPlot is an interface of Python’s ______ library.

(a) seaborn
(b) plotly
(c) ggplot
(d) matplotlib
MCQs - Data Handling: Pandas and Pyplot (Page 7 & 8)

Multiple Choice Questions

UNIT I: DATA HANDLING - PANDAS AND PYPLOT

Page 7 & 8

1. For 2D plotting using a Python library, which library interface is often used?

(a) seaborn
(b) plotly
(c) matplotlib
(d) matplotlib.pyplot

2. Which of the following is not a valid chart type?

(a) Histogram
(b) Statistical
(c) Pie
(d) Box

3. Which of the following is not a valid plotting function of pyplot?

(a) plot()
(b) bar()
(c) line()
(d) pie()

4. Which of the following plotting functions does not plot multiple data series?

(a) plot()
(b) bar()
(c) pie()
(d) barh()

5. The plot which tells the trend between two graphed variables is the ______ graph/chart.

(a) line
(b) scatter
(c) bar
(d) pie

6. Which of the following functions is used to create a line chart?

(a) line()
(b) plot()
(c) chart()
(d) plotline()

7. Which of the following function will produce a bar chart?

(a) plot()
(b) bar()
(c) plotbar()
(d) barh()

8. Which of the following function will create a vertical bar chart?

(a) plot()
(b) bar()
(c) plotbar()
(d) barh()

9. Which of the following function will create a horizontal bar chart?

(a) plot()
(b) bar()
(c) plotbar()
(d) barh()

10. The datapoints plotted on a graph are called ______.

(a) points
(b) pointers
(c) marks
(d) markers

11. A ______ graph is a type of chart which displays information as a series of data points connected by straight line segments.

(a) line
(b) bar
(c) pie
(d) boxplot

12. Which argument of bar() lets you set the thickness of bar?

(a) thick
(b) thickness
(c) width
(d) barwidth

13. Which function lets you set the title of the plot?

(a) title()
(b) plottitle()
(c) graphtitle()
(d) All of these

14. The command used to give a heading to a graph is ______.

(a) plt.show()
(b) plt.plot()
(c) plt.xlabel()
(d) plt.title()

15. Which function would you use to set the limits for x-axis of the plot?

(a) limits()
(b) xlimits()
(c) xlim()
(d) lim()

16. Which function is used to show legends?

(a) display()
(b) show()
(c) legend()
(d) legends()

17. Which argument must be set with plotting functions for legend() to display the legends?

(a) data
(b) label
(c) name
(d) sequence

18. Which function is used to create a histogram?

(a) histo()
(b) histogram()
(c) hist()
(d) histtype

19. Which of the following is not a valid plotting function of pyplot?

(a) plot()
(b) bar()
(c) line()
(d) pie()

20. Which of the following plotting functions does not plot multiple data series?

(a) plot()
(b) bar()
(c) pie()
(d) barh()

21. The plot which tells the trend between two graphed variables is the ______ graph/chart.

(a) line
(b) scatter
(c) bar
(d) pie

22. A CSV file can take ______ character as separator.

(a) ,
(b) ~
(c) |
(d) \t
(e) only (a)
(f) all of these

23. In order to work with CSV files from Pandas, you need to import ______, other than pandas.

(a) csv
(b) pandas.io
(c) newcsv
(d) no extra package required

24. The correct statement to read from a CSV file in a dataframe is:

(a) <DF>.read_csv(<file>)
(b) <File>.read_csv() (<DF>)
(c) <DF> = pandas.read(<file>)
(d) <DF> = pandas.read_csv(<files>)

25. Which argument do you specify with read_csv() to specify a separator character?

(a) character
(b) char
(c) separator
(d) sep

26. To suppress first row as header, which of the following arguments is to be given in read_csv()?

(a) noheader = True
(b) header = None
(c) skipheader = True
(d) header = Null

27. To read specific number of rows from a CSV file, which argument is to be given in read_csv()?

(a) rows = <n>
(b) nrows = <n>
(c) n_rows = <n>
(d) number_rows = <n>

28. To skip first 5 rows of CSV file, which argument will you give in read_csv()?

(a) skiprows = 5
(b) skip_rows = 5
(c) skip = 5
(d) noread = 5

29. To skip 1st, 3rd and 5th rows of CSV file, which argument will you give in read_csv()?

(a) skiprows = 1 | 3 | 5
(b) skiprows = [1, 5, 1]
(c) skiprows = [1, 3, 5]
(d) Any of these

30. While reading from a CSV file, to use a column’s values as index labels, argument given in read_csv() is:

(a) index
(b) index_col
(c) index_values
(d) index_label

31. While writing a dataframe onto a CSV file, which argument would you use in to_sql() for NaN values’ representation as NULL?

(a) NaN = NULL
(b) na_rep = NULL
(c) na_value = NULL
(d) na = NULL
MCQs - Database Query Using SQL (Unit II)

Multiple Choice Questions

UNIT II: DATABASE QUERY USING SQL

MOVE FAST WITH INFORMATICS PRACTICES – XII

1. Which of the following is a group of one or more attributes that uniquely identifies a row?

(a) Key
(b) Determinant
(c) Tuple
(d) Relation

2. Which of the following attributes cannot be considered as a choice for primary key?

(a) Id
(b) License number
(c) Dept_id
(d) Street

3. An attribute in a relation is a foreign key if it is the ______ key in any other relation.

(a) Candidate
(b) Primary
(c) Super
(d) Sub

4. Consider the table with structure as: Student(ID, name, dept_name, tot_cred)

In the above table, which attribute will form the primary key?

(a) Name
(b) Dept
(c) Total_credits
(d) ID

5. Which of the following is not a legal sub-language of SQL?

(a) DDL
(b) QAL
(c) DML
(d) TCL

6. Which of the following attributes can be considered as a choice for primary key?

(a) Name
(b) Street
(c) Roll No
(d) Subject

7. What is the full form of SQL?

(a) Structured Query Language
(b) Structured Query List
(c) Simple Query Language
(d) None of these

8. What is the full form of DDL?

(a) Dynamic Data Language
(b) Detailed Data Language
(c) Data Definition Language
(d) Data Derivation Language

9. What does DML stand for?

(a) Different Mode Level
(b) Data Model Language
(c) Data Mode Lane
(d) Data Manipulation Language

10. Which of the below given tasks cannot be performed through Data Manipulation Language (DML) commands?

(a) Create table in the Database
(b) Insert a record into a table
(c) Delete a record from a table
(d) Modify a record into a table

11. Which is the subset of SQL commands used to manipulate database structures, including tables?

(a) Data Definition Language (DDL)
(b) Data Manipulation Language (DML)
(c) Both (a) and (b)
(d) None

12. Which sublanguage of SQL is used to define the structure of the relation, deleting relations and relating schemas?

(a) DML (Data Manipulation Language)
(b) DDL (Data Definition Language)
(c) Query
(d) Relational Schema

13. Which sublanguage of SQL is used to query information and modify tuples in the database?

(a) DML (Data Manipulation Language)
(b) DDL (Data Definition Language)
(c) Query
(d) Relational Schema

14. Which of the following is a DDL command?

(a) SELECT
(b) ALTER
(c) INSERT
(d) UPDATE

15. Consider following SQL statement. What type of statement is this?

SELECT * FROM employee;
(a) DML
(b) DDL
(c) DCL
(d) Integrity constraint

16. In SQL, which of the following will select only one copy of duplicable rows?

(a) SELECT UNIQUE
(b) SELECT DISTINCT
(c) SELECT DIFFERENT
(d) All of these

17. ______ keyword is used to eliminate duplicates from the query result.

(a) Unique
(b) Union
(c) Different
(d) DISTINCT

18. Best data type for fixed length alphanumeric field in MySQL?

(a) VARCHAR
(b) CHAR
(c) LONG
(d) NUMBER

19. SELECT ______ dept_name FROM Company; (Display unique values)

(a) All
(b) From
(c) Distinct
(d) Name

20. SELECT ______ dept_name FROM Company; (Display all values)

(a) All
(b) From
(c) Distinct
(d) Name

21. The ______ clause allows selecting rows satisfying a condition.

(a) Where
(b) from
(c) having
(d) like

22. Which operator can take wildcard characters?

(a) BETWEEN
(b) LIKE
(c) IN
(d) NOT

23. Which operator checks a value against a range?

(a) BETWEEN
(b) LIKE
(c) IN
(d) NOT

24. Which SQL command retrieves data from table(s)?

(a) UPDATE
(b) SELECT
(c) Union
(d) All of these

25. Which clause is used to sort the query result?

(a) Order By
(b) Sort by
(c) Group By
(d) Arrange By

26. By default, ORDER BY lists results in ______ order.

(a) Descending
(b) Any
(c) Same
(d) Ascending

27. The ______ operator displays a record if all conditions are true.

(a) Or
(b) Null
(c) AND
(d) Not

28. The ______ operator displays a record if one condition is true.

(a) Or
(b) Null
(c) AND
(d) Not

29. Which subset of SQL is used to add, delete and modify data rows?

(a) TCL
(b) DML
(c) DDL
(d) DCL

30. In SQL, which command is used to change table structure?

(a) ALTER TABLE
(b) MODIFY TABLE
(c) CHANGE TABLE
(d) All of these

31. ______ defines rules regarding allowed values in columns.

(a) Column
(b) Constraint
(c) Index
(d) Trigger