CBSE · Class 12 · Informatics Practices

Class 12 Data Handling using Pandas - I Mock Test (CBSE)

5 practice questions from Data Handling using Pandas - I, in the style of your board paper, each with a worked answer and the marks for every step. Then take a full chapter test on paper, snap the pages and get every step marked.

Topics in Data Handling using Pandas - I

  • Introduction to Python libraries
  • Series: creation
  • Accessing elements of a series
  • Attributes and methods of series
  • Mathematical operations on series
  • DataFrame: creation
  • Operations on rows and columns in DataFrames
  • Accessing DataFrame elements through indexing
  • Accessing DataFrame elements through slicing
  • Attributes of DataFrames
  • Importing and exporting data between CSV files and DataFrames
  • Pandas series versus NumPy ndarray

Data Handling using Pandas - I practice questions with answers

  1. Q1Multiple choice1 mark
    Which statement correctly distinguishes the pandas function read_csv() from the DataFrame method to_csv()?
    1. (a)read_csv() writes a DataFrame to a CSV file, while to_csv() reads a CSV file into a DataFrame.
    2. (b)read_csv() reads a CSV file into a DataFrame, while to_csv() writes a DataFrame to a CSV file.
    3. (c)Both read_csv() and to_csv() work only on Series objects and never on DataFrames.
    4. (d)read_csv() returns a NumPy ndarray, while to_csv() returns a Series holding the file contents.
    Show answer and step marks
    1. Correct option: (b) read_csv() reads a CSV file into a DataFrame, while to_csv() writes a DataFrame to a CSV file.+1
    Answer: (b)
  2. Q2Multiple choice1 mark
    Which of the following best describes a Python library?
    1. (a)A file that permanently stores a DataFrame on disk in CSV format.
    2. (b)A single built-in data type used to store a sequence of values.
    3. (c)A graphical window in which Python code is typed and run.
    4. (d)A collection of pre-written modules and functions that is imported with the import statement.
    Show answer and step marks
    1. Correct option: (d) A collection of pre-written modules and functions that is imported with the import statement.+1
    Answer: (d)
  3. Q3Short answer2 marks
    A Series named quiz is created as follows: quiz = pd.Series([78, 85, 62, 90], index=['Asha', 'Ravi', 'Meera', 'Kabir']) (a) Explain how Python decides which element the expression quiz[1] returns, even though 1 is not an index label of this Series. [1] (b) Write the statement that returns the value 62 using its index label. [1]
    Show answer and step marks
    1. (a) The integer 1 is read as a position counted from 0 (zero-based), so quiz[1] selects the second element of the Series, whose value is 85.+1
    2. (b) quiz['Meera'] returns 62, since 'Meera' is the index label of that element.+1
    Answer: (a) An integer in square brackets is treated as a zero-based position, so quiz[1] returns 85, the second element. (b) quiz['Meera']
  4. Q4Short answer3 marks
    The library's stock is stored in a DataFrame named stock, with row labels B1 to B4 and columns Title, Copies and Price, as shown below.
    LabelTitleCopiesPrice
    B1Physics Vol 14450
    B2Algebra Guide2320
    B3English Grammar6275
    B4World Atlas3610
    Write the Python statement for each of the following. (a) Display the number of copies of the book whose row label is 'B3'. [1] (b) Display the Title and Price of the books whose row labels are 'B2' and 'B4', using the row labels. [1] (c) Display the Price of the book in the 4th row, using its position in the DataFrame. [1]
    Show answer and step marks
    1. (a) Uses the row label 'B3' and column label 'Copies' with stock.loc, giving 6.+1
    2. (b) Uses the row labels ['B2', 'B4'] and column labels ['Title', 'Price'] with stock.loc, giving the Title and Price of those two rows.+1
    3. (c) Uses stock.iloc[3, 2] to select row position 3 (4th row) and column position 2 (Price), giving 610.+1
    Answer: (a) stock.loc['B3', 'Copies'] gives 6 (b) stock.loc[['B2', 'B4'], ['Title', 'Price']] gives Algebra Guide 320 and World Atlas 610 (c) stock.iloc[3, 2] gives 610
  5. Q5Short answer3 marks
    A clinic records the details of three admitted patients in the dictionary d given below. The pandas library has been imported as pd. d = {'Name': ['Asha', 'Ravi', 'Meena'], 'Age': [34, 58, 27], 'Ward': ['A1', 'B2', 'A1']} (a) Write the statement to create a DataFrame named clinic from d, so that the rows get the default index 0, 1 and 2. [1] (b) Write the statement to create a DataFrame named clinic2 from d, so that the row labels are 'P101', 'P102' and 'P103'. [2]
    Show answer and step marks
    1. (a) Creates the DataFrame from the dictionary with clinic = pd.DataFrame(d), giving default row labels 0, 1, 2.+1
    2. (b) Passes the dictionary d as the data of pd.DataFrame(d) for clinic2.+1
    3. (b) Sets index=['P101', 'P102', 'P103'] so that these are the row labels.+1
    Answer: (a) clinic = pd.DataFrame(d) (b) clinic2 = pd.DataFrame(d, index=['P101', 'P102', 'P103'])

Take a full Data Handling using Pandas - I test

PrepitUp writes a fresh paper on this chapter at the length you pick. Write it on paper with a timer, photograph the pages, and see the marks for every step and what to practise next.

  • 15 min10 marks
  • 30 min20 marks
  • 1.5 hr40 marks
  • 3 hr80 marks
See a sample marked answer sheet

Get your Data Handling using Pandas - I answers marked

Sign in, pick this chapter and a length, write the test on paper and get every step marked.

Sign in to take this test

More Class 12 Informatics Practices mock tests