12.6.1: Review Questions
- Page ID
- 58347
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\dsum}{\displaystyle\sum\limits} \)
\( \newcommand{\dint}{\displaystyle\int\limits} \)
\( \newcommand{\dlim}{\displaystyle\lim\limits} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\(\newcommand{\longvect}{\overrightarrow}\)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\ket}[1]{\left| #1 \right>}\)
\(\newcommand{\bra}[1]{\left< #1 \right|}\)
\(\newcommand{\braket}[2]{\left< #1 \vphantom{#2} \right| \left. #2 \vphantom{#1} \right>}\)
\(\newcommand{\braopket}[3]{\left< #1 \vphantom{#2}\vphantom{#3} \right| #2 \vphantom{#1}\vphantom{#3} \left| #3 \vphantom{#1}\vphantom{#2} \right>}\)
\(\newcommand{\qmvec}[1]{\mathbf{\vec{#1}}}\)
\(\newcommand{\op}[1]{\hat{\mathbf{#1}}}\)
\(\newcommand{\expect}[1]{\langle #1 \rangle}\)
\(\newcommand{\dfn}[1]{\emph{\textbf{#1}}}\)
Review Questions
Multiple Choice
-
Which pandas function reads a CSV file into a DataFrame?
-
a) pd.load_csv() b) pd.read_csv() c) pd.import_csv() d) pd.open_csv()
-
-
In R's dplyr, which verb is used to create new calculated columns?
-
a) filter() b) select() c) mutate() d) arrange()
-
-
A SQL window function like ROW_NUMBER() OVER (PARTITION BY dept ORDER BY salary DESC) does what?
-
a) Deletes duplicate rows b) Assigns a rank within each department by salary c) Groups and aggregates by department d) Joins two tables
-
Short Answer
-
Compare pandas (Python) and dplyr (R) for data manipulation. Write equivalent code in both languages to: filter rows where region = "North", group by product, and sum revenue.
-
Explain what a Jupyter Notebook is and why it's valuable for analytics. How does it support reproducibility?
-
When would you use SQL for analytics versus Python/R? Describe a scenario where SQL is the better choice and one where Python is preferable.
-
What is a SQL window function? How does it differ from GROUP BY aggregation? Provide an example showing a running total.
True/False
-
True or False: pandas DataFrames can only hold numeric data.
-
True or False: R Markdown documents can include Python code chunks alongside R code.
-
True or False: SQL CTEs (WITH clauses) create permanent tables in the database.
Answer Key:
1-b, 2-c, 3-b, 4. Python: df[df['region']=='North'].groupby('product')['revenue'].sum(). R: df %>% filter(region == "North") %>% group_by(product) %>% summarise(total = sum(revenue)). 5. Jupyter = interactive document with code cells, markdown text, and outputs (charts, tables) in one place. Supports reproducibility because anyone can re-run the notebook to regenerate all results; combines code, documentation, and output. 6. SQL better: querying large databases directly, aggregation/joins that the database engine optimizes (e.g., summarizing 100M rows in a warehouse). Python better: complex data transformations, ML modeling, custom visualizations, working with unstructured data (text, images). 7. Window function computes a value for each row using related rows WITHOUT collapsing the result — unlike GROUP BY which reduces rows. Example: SUM(revenue) OVER (ORDER BY date ROWS UNBOUNDED PRECEDING) gives a running total where each row shows cumulative revenue up to that date. 8. False, 9. True, 10. False (CTEs are temporary, existing only for the query).


