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

Chapter 7 exercises: Data Input and Output

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-07-E01 · Inspect an API envelope

Report whether acquisition is complete. Do not treat the first two records as all records.

response=[{"page":1,"pages":3},[{"id":7},{"id":8}]]
One hint after an attempt

Read metadata before the record list.

B2-07-E02 · Parameterize an SQL filter

Load a disposable in-memory SQLite table and select year 2023 using a parameter, with names sorted.

df=pd.DataFrame({"name":["N","S","E"],"year":[2022,2023,2023]})
One hint after an attempt

Use ? and a one-item parameter tuple.

B2-07-E03 · Verify a snapshot fingerprint

Compute a SHA-256 fingerprint and demonstrate that one changed byte changes it. Explain what the hash cannot prove.

raw=b"id,value\n1,3\n"
One hint after an attempt

Compare the same bytes with a modified copy.

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-07-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.