Worksheets › Class 12 › Data Handling using Pandas – I

Class 12 · Informatics Practices worksheet

Data Handling using Pandas – I

CBSE Informatics Practices. Series and DataFrames: creation, loc and iloc, slicing, head and tail, Boolean indexing, adding and dropping rows and columns, shape and size, CSV files. Every sheet has 20 questions in three sections and an answer key, and the questions change every time.

Open a printable sample sheet

Sample questions

Real questions from this chapter, as the app sets them. Tap Answer to see the answer and working.

Section A · multiple choice

  1. 1.

    A pandas Series is:

    1. a kind of chart
    2. a database server
    3. a two-dimensional table
    4. a one-dimensional labelled array
    Answer

    (d) a one-dimensional labelled array

  2. 2.

    Series s: A | 83 B | 80 C | 72 D | 85 E | 66 Which labels does s.iloc[0:2] show?

    1. B
    2. A
    3. A, B
    4. A, B, C, D, E
    Answer

    (c) A, B

    iloc slices by position: 0 up to, not including, 2

  3. 3.

    Series s: Mon | 60 Tue | 42 Wed | 54 Thu | 55 Fri | 58 Sat | 75 Which values does print(s[s > 58]) show?

    1. 60, 75
    2. 60, 58, 75
    3. 60, 54, 75
    4. 42, 54, 55, 58
    Answer

    (a) 60, 75

    keeps the elements where s > 58

Section B · short answer

  1. 4.

    Give two differences between a Series and a DataFrame.

    Answer

    A Series is one-dimensional and has one index; a DataFrame is two-dimensional with a row index and column labels. A Series holds values of one column; a DataFrame can hold several columns of different types.

  2. 5.

    Series s: Jan | 74 Feb | 62 Mar | 59 Apr | 29 May | 76 Write the output of: print(s.loc['Jan':'May'].sum())

    Answer

    300

    Jan to May, both included: 74 + 62 + 59 + 29 + 76

Section C · long answer

  1. 6.

    Explain how a DataFrame can be created from (a) a dictionary of lists, (b) a list of dictionaries, (c) a CSV file. Write one statement for each.

    Answer

    (a) pd.DataFrame({'Name': ['Asha', 'Ravi'], 'Marks': [78, 85]}): keys become columns. (b) pd.DataFrame([{'Name': 'Asha', 'Marks': 78}, {'Name': 'Ravi', 'Marks': 85}]): each dictionary is a row. (c) pd.read_csv('marks.csv'): the file’s first line gives the column names.

    one mark each; one for correct explanation

Fresh sheets for your child

In the app, every Data Handling using Pandas – I sheet is new: the app remembers the questions your child has already had and leaves them out. Print the sheet as a PDF, or use notebook mode and write the answers in a notebook.

Coming soon for Android and iPhone.

More Class 12 Informatics Practices