🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Data Science & Analytics › Capstone with Real City/Urbanicity Data › Lesson 2
TEC-DATA85-11 · Lesson 2 · 10 clock hours · lab

Data Acquisition and Metadata Documentation

Objective. Students programmatically download or API-pull their chosen city datasets, inspect metadata and data dictionaries, and populate a standardized data-source log that records provenance, update frequency, and known limitations.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

Data Acquisition and Metadata Documentation

Why Provenance Matters

Before any analysis can be trusted, you must know exactly where your data came from, when it was collected, who maintains it, and what its known limitations are. In professional data science, undocumented data is treated as unreliable data. City and municipal open-data portals publish datasets that are genuinely useful — permit records, 311 service calls, traffic counts, crime reports — but they vary widely in completeness, update frequency, and licensing terms. Your job in this lab is to pull those datasets programmatically, inspect them carefully, and document every important fact about each source in a standardized data-source log before you build a single chart or model.

Open-Data APIs and the Socrata Platform

Many US cities host their open-data portals on a platform called Socrata, which exposes datasets through a consistent REST API called SODA (Socrata Open Data API). Chicago, New York, Los Angeles, San Francisco, and dozens of smaller cities all use this platform. The API returns data in JSON (or CSV) and supports URL-based query parameters such as `$limit`, `$offset`, `$where`, and `$select`. You authenticate with an app token — a free API key you register on the portal — which raises your rate limit and identifies your application.

A basic Python `requests` call to a Socrata endpoint looks like this:

```python

import requests

import pandas as pd

url = "https://data.cityofchicago.org/resource/ijzp-q8t2.json"

params = {"$limit": 5000, "$$app_token": "YOUR_TOKEN_HERE"}

response = requests.get(url, params=params)

response.raise_for_status() # raises an error on HTTP 4xx/5xx

df = pd.DataFrame(response.json())

print(df.dtypes)

print(df.isnull().sum())

```

Always call `raise_for_status()` immediately after the request. This converts silent HTTP error codes into Python exceptions, so problems surface early rather than corrupting downstream analysis.

Inspecting Columns and Data Types

Once data is in a DataFrame, your first moves are defensive:

1. Check column data types — numeric fields imported from JSON often arrive as strings. Cast them explicitly.

2. Count nulls per column — a field that is 40 % null may be unusable for your research question.

3. Check date ranges — confirm the data covers the period you need.

4. Look for duplicates — use `df.duplicated().sum()` before loading anything.

5. Cross-reference the official data dictionary — the portal's dataset page or a linked PDF defines what each column means, its unit of measure, and any known coding issues.

Never assume a column name is self-explanatory. "Status" in one city's permit dataset means something different from "Status" in another city's inspection dataset.

Loading into PostgreSQL

Storing acquired data in PostgreSQL rather than raw CSV files gives you a versioned, queryable record of what you ingested and when. Use `psycopg2` to write DataFrames row by row, or use `pandas.DataFrame.to_sql()` with a SQLAlchemy engine pointed at your local PostgreSQL 15 instance. Create a dedicated schema for each data source and add an `ingested_at` timestamp column so you always know when you pulled the data.

```python

from sqlalchemy import create_engine

engine = create_engine("postgresql+psycopg2://user:password@localhost:5432/capstone")

df["ingested_at"] = pd.Timestamp.utcnow()

df.to_sql("chicago_crimes_raw", engine, schema="city_data",

if_exists="replace", index=False)

```

Use `if_exists="replace"` during early development, but switch to `"append"` with deduplication logic once your pipeline stabilizes.

Completing the Data-Source Log

The data-source log is a structured spreadsheet with one row per dataset. Required fields for this program are:

This log is not a formality. It is the foundation of your methodology section and the document a peer must use to reproduce your work independently.

Pair Review and Reproducibility

Reproducibility is a professional standard. After you complete your log, you swap it with a classmate. Your partner's only inputs are the URL, API parameters, and app token instructions you documented. If they cannot retrieve the same dataset and get a row count within a reasonable margin, your documentation has a gap. Fix every flagged item before submitting. This mirrors how data engineering teams conduct peer reviews of data pipelines.

Credential Connections

This lab maps directly to CompTIA Data+ Domain 1 (data acquisition and quality), which tests knowledge of data sources, metadata, data dictionaries, and data governance. Google Data Analytics and IBM Data Science Professional both emphasize documented, reproducible workflows. Microsoft PL-300 candidates must understand data source connections and refresh settings — the same provenance concepts you practice here.

A Note on Data Ethics and Licensing

Open does not mean unrestricted. Read the license for every dataset. Some city portals require attribution; a few restrict commercial use. Check whether the dataset contains any personally identifiable information (PII) — even publicly posted data can raise privacy concerns when combined with other sources. Document the license in your log and flag any PII-adjacent fields (name, address, birth date) so your team can handle them appropriately.

Key terms9

Socrata Open Data API (SODA)A REST API standard used by many US city open-data portals that allows programmatic access to datasets via URL-based query parameters, returning data in JSON or CSV format.
ProvenanceThe documented origin and history of a dataset, including its source, collection method, owner, and any transformations applied — essential for reproducibility and trust.
Data dictionaryAn official reference document that defines every column in a dataset, including its name, data type, unit of measure, allowed values, and any known coding conventions.
Data-source logA standardized record that captures provenance, licensing, date range, row count, column definitions, update frequency, and known limitations for each dataset used in a project.
API app tokenA credential issued by an open-data portal that authenticates your application, raises your request rate limit, and identifies your usage — required for sustained programmatic access to Socrata portals.
Null / missing valueA cell in a dataset that contains no recorded value, which must be counted, understood, and handled explicitly before analysis because it can silently distort results.
Ingestion timestampA datetime value added to each record when it is loaded into a database, recording exactly when the data was pulled so analysts can reconstruct the state of the source at that moment.
Rate limitA server-imposed cap on the number of API requests an application may make within a given time window, exceeded requests return HTTP 429 errors and must be handled with retry logic or delays.
Open licenseA legal instrument such as CC0, Public Domain, or ODC-PDDL that grants the public broad rights to use, share, and modify a dataset, though specific terms vary and must be read carefully.
In class: Live coding demo: instructor pulls a Chicago or similar city dataset via a Socrata open-data API using Python requests library, inspects column types, checks for missing fields, and writes results to a local PostgreSQL database; students replicate steps on their own chosen dataset. · Students complete a data-source log spreadsheet (schema, row count, column definitions, date range, licensing, known caveats) for each dataset they plan to use, cross-referencing the official data dictionary PDF where available. · Pair review: students swap data-source logs, attempt to locate the same dataset independently using only the documented URL and API parameters, and flag any gaps; discrepancies are corrected before submission.
Materials: Python 3 with pandas, requests, psycopg2; PostgreSQL 15; Jupyter Notebook; city open-data portal API keys; data-source log template (Excel/CSV); CompTIA Data+ official study guide (domain 1 — data acquisition and quality).
Check: Instructor inspects data-source log and queries the student's PostgreSQL database; pass requires at least two datasets loaded without import errors, log contains all required fields for each source, and a peer reviewer was able to reproduce the download — all three criteria met = pass.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

CompTIA Data+ — Data Acquisition and Quality
1. You call `response.raise_for_status()` immediately after a `requests.get()` call. What is the primary benefit of this practice?
CompTIA Data+ — Data Acquisition and Quality
2. A classmate's data-source log lists the dataset name and URL but omits the API query parameters used. During peer review, you pull the endpoint without those parameters and receive 1,000 rows instead of the expected 47,000. What is the most likely cause?
IBM Data Science Professional — Data Engineering Fundamentals
3. When loading a DataFrame into PostgreSQL using `pandas.DataFrame.to_sql()`, which `if_exists` setting should you prefer once your pipeline is stable and you want to add new records without deleting previously ingested data?
CompTIA Data+ — Data Quality and Governance
4. A city dataset on building permits lists a column named 'STATUS.' The data dictionary PDF defines three valid values: ISSUED, PENDING, and CLOSED. Your DataFrame shows a fourth value, 'VOID,' in about 2% of rows. What should you do first?
Google Data Analytics — Data Preparation and Validation
5. Which field in a data-source log most directly supports a future analyst's ability to assess whether a dataset is still current enough for their research question?
CompTIA Data+ — Data Governance, Quality, and Controls
6. You discover that a city crime dataset you plan to use contains a full street address for every incident. Under which concept should you flag this in your data-source log?
Google Data Analytics — Data Ethics and Integrity
7. A dataset is published under the Creative Commons CC0 license. What does this mean for your capstone project?
CompTIA Data+ — Data Acquisition and Quality
8. During peer review, your partner successfully retrieves your dataset using only the URL and parameters in your log, but the row count they obtain is 43,200 compared to your logged count of 47,000. The most professionally responsible next step is to:
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.