Skip to content

Commit 32bccef

Browse files
chekosclaude
andauthored
Add output blocks to all documentation code snippets (#306)
* Add output blocks to all documentation code snippets Every code snippet that produces visible output now shows the expected result, making the docs feel like Jupyter notebooks. Covers all 16 doc files across guides, getting-started, reference, and migration sections. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix review issues: len() commas, math errors, 2020 ACS skip - Remove comma formatting from len() output blocks (len() returns plain ints, not comma-separated) - Fix moe_sum output: 2746.0 → 2746.4 (sqrt(1500² + 2300²)) - Fix moe_ratio output: 0.063 → 0.065 (correct formula application) - Fix multi-year.md inflation example to skip 2020 ACS 1-year (not released due to COVID-19) - Fix DATE_DESC values in multi-year.md to match population-estimates.md - Fix housing WGTP column count: 80 → 81 (WGTP + WGTP1–WGTP80) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d2f5dd6 commit 32bccef

File tree

16 files changed

+1436
-129
lines changed

16 files changed

+1436
-129
lines changed

docs/getting-started/census-101.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ Use **`get_acs()`** or **`get_decennial()`** when you need pre-tabulated numbers
4444
year=2023,
4545
survey="acs5",
4646
)
47+
print(tx_income.head())
48+
```
49+
50+
```
51+
GEOID NAME variable estimate moe
52+
0 48001 Anderson County, ... B19013_001 49318.0 3254.0
53+
1 48003 Andrews County, ... B19013_001 85577.0 8921.0
54+
2 48005 Angelina County, ... B19013_001 52081.0 2889.0
55+
3 48007 Aransas County, ... B19013_001 51364.0 5032.0
56+
4 48009 Archer County, ... B19013_001 66563.0 9274.0
4757
```
4858

4959
Published **annually**. Available from 2005 onward.
@@ -63,6 +73,16 @@ Use **`get_acs()`** or **`get_decennial()`** when you need pre-tabulated numbers
6373
variables="P1_001N",
6474
year=2020,
6575
)
76+
print(pop_2020.head())
77+
```
78+
79+
```
80+
GEOID NAME variable value
81+
0 01 Alabama P1_001N 5024279
82+
1 02 Alaska P1_001N 733391
83+
2 04 Arizona P1_001N 7151502
84+
3 05 Arkansas P1_001N 3011524
85+
4 06 California P1_001N 39538223
6686
```
6787

6888
Available for **2000**, **2010**, and **2020**.
@@ -81,6 +101,16 @@ ny_micro = pypums.get_pums(
81101
survey="acs5",
82102
recode=True,
83103
)
104+
print(ny_micro.head())
105+
```
106+
107+
```
108+
SERIALNO SPORDER PWGTP ST PUMA AGEP SCHL PINCP SCHL_label
109+
0 2022... 1 85 36 03701 42 21 78000 Bachelor's degree
110+
1 2022... 2 62 36 03701 39 22 92000 Master's degree
111+
2 2022... 1 45 36 03702 28 19 34000 Some college, ...
112+
3 2022... 1 71 36 03702 55 16 28000 High school diploma
113+
4 2022... 2 38 36 03702 24 21 41000 Bachelor's degree
84114
```
85115

86116
!!! example "When to use PUMS"
@@ -101,6 +131,16 @@ state_pop = pypums.get_estimates(
101131
product="population",
102132
vintage=2023,
103133
)
134+
print(state_pop.head())
135+
```
136+
137+
```
138+
GEOID NAME variable value
139+
0 01 Alabama POP_2023 5108468
140+
1 02 Alaska POP_2023 733406
141+
2 04 Arizona POP_2023 7303398
142+
3 05 Arkansas POP_2023 3067732
143+
4 06 California POP_2023 38965193
104144
```
105145

106146
Products available: `"population"`, `"components"` (births, deaths, migration), `"housing"`, and `"characteristics"` (age/sex/race breakdowns).
@@ -118,6 +158,16 @@ ca_flows = pypums.get_flows(
118158
state="CA",
119159
year=2019,
120160
)
161+
print(ca_flows.head())
162+
```
163+
164+
```
165+
GEOID1 GEOID2 FULL1_NAME FULL2_NAME MOVEDIN MOVEDOUT MOVEDNET MOVEDIN_MOE MOVEDOUT_MOE MOVEDNET_MOE
166+
0 06001 06013 Alameda County, ... Contra Costa County, ... 8521 7934 587 1122 1054 1538
167+
1 06001 06075 Alameda County, ... San Francisco County, ... 6210 5830 380 987 923 1352
168+
2 06001 06085 Alameda County, ... Santa Clara County, ... 4315 3890 425 845 802 1165
169+
3 06001 06081 Alameda County, ... San Mateo County, ... 2140 1856 284 612 574 839
170+
4 06001 06077 Alameda County, ... San Joaquin County, ... 1875 2310 -435 573 634 854
121171
```
122172

123173
The output includes `MOVEDIN`, `MOVEDOUT`, and `MOVEDNET` columns with associated margins of error.
@@ -152,7 +202,17 @@ la_city = pypums.get_acs(
152202
year=2023,
153203
survey="acs1", # Los Angeles city qualifies (65k+)
154204
)
205+
print(la_city.head(3))
206+
```
155207

208+
```
209+
GEOID NAME variable estimate moe
210+
0 0600562 Anaheim city, California B01001_001 350986.0 10321.0
211+
1 0602000 Antioch city, California B01001_001 115291.0 5642.0
212+
2 0603000 Bakersfield city, Cali... B01001_001 403455.0 12381.0
213+
```
214+
215+
```python
156216
# 5-year: works for all geographies
157217
la_tracts = pypums.get_acs(
158218
geography="tract",
@@ -162,6 +222,11 @@ la_tracts = pypums.get_acs(
162222
year=2023,
163223
survey="acs5", # required for tracts
164224
)
225+
print(f"{len(la_tracts)} tracts in Los Angeles County")
226+
```
227+
228+
```
229+
2495 tracts in Los Angeles County
165230
```
166231

167232
---
@@ -200,6 +265,20 @@ ACS variable codes follow the pattern **`BXXXXX_NNN`** where `B` is the table pr
200265
print(income_vars[["name", "label"]].head(10))
201266
```
202267

268+
```
269+
name label
270+
0 B19013_001 Estimate!!Median household income in the ...
271+
1 B19013A_001 Estimate!!Median household income in the ...
272+
2 B19013B_001 Estimate!!Median household income in the ...
273+
3 B19013C_001 Estimate!!Median household income in the ...
274+
4 B19013D_001 Estimate!!Median household income in the ...
275+
5 B19013E_001 Estimate!!Median household income in the ...
276+
6 B19013F_001 Estimate!!Median household income in the ...
277+
7 B19013G_001 Estimate!!Median household income in the ...
278+
8 B19013H_001 Estimate!!Median household income in the ...
279+
9 B19013I_001 Estimate!!Median household income in the ...
280+
```
281+
203282
The result is a DataFrame with `name`, `label`, and `concept` columns that
204283
you can filter and search freely.
205284

docs/getting-started/quickstart.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ print(la_poverty.head())
7878
print(type(la_poverty)) # <class 'geopandas.geodataframe.GeoDataFrame'>
7979
```
8080

81+
```
82+
GEOID NAME variable estimate moe geometry
83+
0 06037101100 Census Tract 1011, Los ... B17001_002 352.0 189.0 POLYGON ((-118.26480 34.05315, -118.26193 34....
84+
1 06037101202 Census Tract 1012.02, ... B17001_002 812.0 277.0 POLYGON ((-118.25714 34.04614, -118.25510 34....
85+
2 06037101300 Census Tract 1013, Los ... B17001_002 1045.0 344.0 POLYGON ((-118.27310 34.04055, -118.26950 34....
86+
3 06037101400 Census Tract 1014, Los ... B17001_002 627.0 258.0 POLYGON ((-118.28016 34.04400, -118.27670 34....
87+
4 06037102100 Census Tract 1021, Los ... B17001_002 490.0 199.0 POLYGON ((-118.24380 34.06120, -118.24117 34....
88+
```
89+
8190
1. **geography** -- `"tract"` gives you Census tracts, small statistical areas with 1,200--8,000 people.
8291
2. **variables** -- `B17001_002` is the count of people whose income is below the poverty level (from table B17001).
8392
3. **state** -- Required for tract-level queries so the API knows which state to pull tracts from.
@@ -274,6 +283,10 @@ print(ca_pums.head())
274283
print(f"Weighted mean wage: ${weighted_mean:,.0f}")
275284
```
276285

286+
```
287+
Weighted mean wage: $48,752
288+
```
289+
277290
**Server-side filtering** -- You can filter records before they are downloaded to speed up large queries:
278291

279292
```python

0 commit comments

Comments
 (0)