pbPassingBI
/
8 questions

Python basics for data — quiz

8 questions covering this module. Just enough language to be productive with data.

  1. Why can a working notebook fail for someone else?

    1. Version differences only
    2. Cells may have been run out of order
    3. Jupyter is unreliable
    4. Missing internet

    Answer: Cells may have been run out of order — Restart & Run All is the check that catches it.

  2. Which library reads .xlsx files?

    1. numpy
    2. openpyxl
    3. seaborn
    4. requests

    Answer: openpyxl — pandas needs openpyxl installed to use read_excel.

  3. '10' + '5' returns:

    1. 15
    2. '105'
    3. An error
    4. 105

    Answer: '105' — String concatenation, not addition. Convert first.

  4. int(3.9) returns:

    1. 4
    2. 3
    3. 3.9
    4. An error

    Answer: 3 — int() truncates toward zero. round() gives 4.

  5. cities[0:2] on a 4-item list returns:

    1. 3 items
    2. 2 items
    3. 4 items
    4. An error

    Answer: 2 items — Slices are end-exclusive throughout Python.

  6. In pd.DataFrame({'a': [1,2]}), the key 'a' becomes:

    1. A row
    2. A column
    3. An index
    4. A data type

    Answer: A column — Dictionary keys become column names.

  7. Why avoid looping over DataFrame rows?

    1. It is invalid
    2. Vectorised column operations are far faster and clearer
    3. Loops cannot access columns
    4. It uses more memory only

    Answer: Vectorised column operations are far faster and clearer — Often around 100x slower, and less readable.

  8. Python combines conditions with:

    1. && and ||
    2. and / or / not
    3. AND / OR
    4. + and -

    Answer: and / or / not — The word forms are the Python syntax.