Chapter 13 exercises: Reproducible Analysis and Reporting
On this page
Attempt these tasks before opening the worked answers. Use the chapter experiment notebook, or import NumPy as np and Pandas as pd in your own notebook. Retain your first attempt and explain each correction.
B2-13-E01 · Fail on an invalid contract
Write a validation function that raises ValueError when id is not unique.
df=pd.DataFrame({"id":[1,1],"value":[3,4]})One hint after an attempt
Validate before transforming.
B2-13-E02 · Combine partial means correctly
Compute the overall mean from sums and counts, and demonstrate why the equal mean of chunk means differs.
chunks=[np.array([2.,4.]),np.array([10.])]One hint after an attempt
Retain sufficient partial statistics.
B2-13-E03 · Preserve transformation inputs
Write a function returning a doubled value column without mutating source.
source=pd.DataFrame({"id":[1,2],"value":[4,8]})One hint after an attempt
Use assign on the received frame.
Reflect and get feedback
Explain one result without looking at the code. Identify one boundary case that would change your method. An optional tutor prompt is: “Here is my attempt at B2-13-E03. Give one hint about the violated assumption; do not give the solution yet.” Then use the worked answers.