pbPassingBI
/

Python full mock exam

15 questions sampled across all 5 modules. Timed like the real thing: answer everything, then review the explanations.

  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. '10' + '5' returns:

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

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

  3. 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.

  4. How do you stop 07030 becoming 7030?

    1. astype(int)
    2. dtype={'zip': str} when reading
    3. parse_dates
    4. encoding="utf-8"

    Answer: dtype={'zip': str} when reading — Read identifier-like columns as strings.

  5. An integer column showing float64 usually indicates:

    1. A bug
    2. Missing values are present
    3. Large numbers
    4. Wrong encoding

    Answer: Missing values are present — NaN forces the column to float.

  6. df[df['a'] > 1 and df['b'] < 5] raises an error because:

    1. a is not numeric
    2. pandas requires & rather than and
    3. Brackets are wrong
    4. It needs .loc

    Answer: pandas requires & rather than and — The "truth value is ambiguous" error means and was used instead of &.

  7. mean() on 100 values with 40 missing divides by:

    1. 100
    2. 60
    3. 40
    4. It errors

    Answer: 60 — Missing values are skipped entirely.

  8. To keep the most recent record per email:

    1. drop_duplicates() alone
    2. Sort by date, then drop_duplicates(keep="last")
    3. dropna()
    4. groupby(email)

    Answer: Sort by date, then drop_duplicates(keep="last") — Without sorting, which row survives is arbitrary.

  9. str.split(" ", n=1, expand=True) returns:

    1. A list
    2. A DataFrame of the split parts
    3. A string
    4. A Series of lists

    Answer: A DataFrame of the split parts — expand=True gives columns you can assign directly.

  10. Which keeps the original row count?

    1. agg
    2. transform
    3. sum
    4. count

    Answer: transform — transform aligns the result back onto every row, like a window function.

  11. df['x'].rank() on tied values gives, by default:

    1. Sequential integers
    2. The average rank, e.g. 2.5
    3. The lowest rank
    4. An error

    Answer: The average rank, e.g. 2.5 — method="min" or "dense" match SQL behaviour.

  12. Which argument raises an error if the relationship is not as expected?

    1. indicator
    2. validate
    3. suffixes
    4. how

    Answer: validate — validate='many_to_one' checks the key relationship.

  13. Why call savefig before show?

    1. It is faster
    2. show clears the figure, producing a blank file
    3. savefig needs the window
    4. Order does not matter

    Answer: show clears the figure, producing a blank file — A classic cause of empty PNGs.

  14. Why must a bar chart y-axis start at zero?

    1. Convention
    2. Bar length encodes value, so truncation misleads
    3. It errors otherwise
    4. For colour scaling

    Answer: Bar length encodes value, so truncation misleads — A truncated axis exaggerates small differences.

  15. Which shows median, quartiles and outliers per category?

    1. Histogram
    2. Box plot
    3. Scatter
    4. Heatmap

    Answer: Box plot — Box plots compare distributions across categories.