Python basics for data — quiz
8 questions covering this module. Just enough language to be productive with data.
Why can a working notebook fail for someone else?
- Version differences only
- Cells may have been run out of order
- Jupyter is unreliable
- Missing internet
Answer: Cells may have been run out of order — Restart & Run All is the check that catches it.
Which library reads .xlsx files?
- numpy
- openpyxl
- seaborn
- requests
Answer: openpyxl — pandas needs openpyxl installed to use read_excel.
'10' + '5' returns:
- 15
- '105'
- An error
- 105
Answer: '105' — String concatenation, not addition. Convert first.
int(3.9) returns:
- 4
- 3
- 3.9
- An error
Answer: 3 — int() truncates toward zero. round() gives 4.
cities[0:2] on a 4-item list returns:
- 3 items
- 2 items
- 4 items
- An error
Answer: 2 items — Slices are end-exclusive throughout Python.
In pd.DataFrame({'a': [1,2]}), the key 'a' becomes:
- A row
- A column
- An index
- A data type
Answer: A column — Dictionary keys become column names.
Why avoid looping over DataFrame rows?
- It is invalid
- Vectorised column operations are far faster and clearer
- Loops cannot access columns
- It uses more memory only
Answer: Vectorised column operations are far faster and clearer — Often around 100x slower, and less readable.
Python combines conditions with:
- && and ||
- and / or / not
- AND / OR
- + and -
Answer: and / or / not — The word forms are the Python syntax.