Data Analysis with Python: From Raw Data to Real-World Insights
BOOK 2 · APPLIED ANALYSIS · CHAPTER 12

Chapter 12 worked answers: Diagnostic Visualization for Analysis

On this page

Compare your reasoning after an attempt. Different valid implementations are welcome when they preserve the observation set and the stated meaning.

B2-12-E01 · Specify a plotted observation

Select the scatterplot population and report both included and excluded counts.

A point needs both coordinates; the plotted denominator differs from the full table.

df=pd.DataFrame({"mass":[3.,None,5.],"length":[1.,2.,3.]})
shown=df.dropna(subset=["mass","length"])
assert len(shown)==2 and len(df)-len(shown)==1
print(len(shown),len(df)-len(shown))
2 1

B2-12-E02 · Inspect histogram sensitivity

Compare counts with two and four equal-width bins. Do not infer a population mode solely from one bin choice.

The observations are unchanged while the visual partition changes. Counts must still sum to six.

x=np.array([1.,1.2,1.3,2.,2.1,4.])
two,_=np.histogram(x,bins=2);four,_=np.histogram(x,bins=4)
assert two.sum()==four.sum()==6
print(two,four)
[5 1] [3 2 0 1]

B2-12-E03 · Choose a diagnostic view

Order categories by count for a bar display and explain why a connected line would imply an unsupported ordering.

The categories are nominal. Ordered bars communicate rank without implying a continuous trajectory between categories.

counts={"A":12,"B":7,"C":20}
ordered=sorted(counts,key=counts.get,reverse=True)
assert ordered==["C","A","B"]
print(ordered)
['C', 'A', 'B']

Return to practice

Change one supplied input, predict the effect and rerun your own implementation. Return to the exercise prompts to identify a task you can now explain independently.

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