Data Analysis with Python: From Raw Data to Real-World Insights
BOOK 2 · PANDAS · CHAPTER 10

Chapter 10 exercises: Operations, GroupBy and Exploratory Analysis

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-10-E01 · Count support correctly

Report row count and observed-value count for each group.

df=pd.DataFrame({"group":["A","A","B"],"value":[2,None,5]})
One hint after an attempt

Compare size and count on the same group.

B2-10-E02 · Compare weights

Calculate the mean subgroup proportion and pooled proportion; explain their different weighting.

success=np.array([9,30])
total=np.array([10,60])
One hint after an attempt

Write both denominators in words.

B2-10-E03 · Check a subgroup reversal

Verify that A has the higher rate in both tasks while B has the higher pooled rate.

a_success=np.array([9,20]);a_total=np.array([10,100])
b_success=np.array([80,1]);b_total=np.array([100,10])
One hint after an attempt

Compare each task before summing.

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-10-E03. Give one hint about the violated assumption; do not give the solution yet.” Then use the worked answers.

Teaching edition · verified experiments · PDF and EPUB editions not generated.