Part V — The Modern Experience Layer · Chapter 29 · Lesson 2 of 2
SQL over records, reports and charts
Records in PeaLang are queryable: analysis.sql runs real SQL — GROUP BY, window functions, CTEs — on in-memory record lists via SQLite. It is the fastest way to answer a structured question about data you already loaded.
SQL over records
let result = analysis.sql(df, """
SELECT city,
SUM(amount) AS revenue,
COUNT(*) AS orders
FROM orders
WHERE status = 'paid'
GROUP BY city
HAVING SUM(amount) > 10000
ORDER BY revenue DESC
""")
let top = analysis.sql_value(df, "SELECT MAX(amount) FROM orders")
CTEs and window functions work: WITH paid AS (...) SELECT ... ROW_NUMBER() OVER (PARTITION BY city ORDER BY amount DESC). Think of it as read-only SQLite with a records driver; it is not a warehouse.
Reports people actually read
analysis.write_report_html({
"title": "Weekly orders",
"sections": [
{ "heading": "Summary", "body": summary },
{ "heading": "By city", "body": analysis.to_html(by_city) }
]
}, "weekly.html")
analysis.profile_markdown(df) # null map + stats as markdown
analysis.write_report_markdown(report, "weekly.md")
The report builders (report_markdown / report_html / model_markdown / evaluation_markdown) exist so the artifact of your analysis is a document, not a terminal scrollback. They compose with the chart writers below.
Charts without a plotting library
analysis.bar_chart_svg(by_city, { "x": "city", "y": "revenue" })
analysis.line_chart_svg(daily, { "x": "date", "y": "orders" })
analysis.scatter_plot_svg(df, { "x": "spend", "y": "revenue" })
analysis.histogram_svg(df, { "col": "amount", "bins": 20 })
print analysis.ascii_bar_chart(by_city) # for terminals
SVG outputs embed cleanly in HTML reports and docs; the ASCII variants are for logs, REPLs and CI output where images are impossible.
Model persistence
When the analysis produces a fitted artifact: save_model / load_model / export_model / import_model serialize it to a portable bundle; model_summary prints what you fitted. The governed-lifecycle material is in Chapters 19–20; this is the minimal persistence story for the analysis itself.
std.stats — for when you need inference
Descriptive stats, distributions (normal_* / poisson_* / binomial_*), hypothesis tests (t_test_ind, welch_t_test, chi_square_test, anova_oneway, mann_whitney_u), confidence intervals, bootstrap_ci, effect sizes, regression with diagnostics (ols, glm, ridge, lasso), time-series tools (acf/pacf, seasonal_decompose, adf_test, arima, auto_arima) and causal estimators (ipw_ate, difference_in_differences, regression_discontinuity). Pure Python, no NumPy or SciPy — it is intentionally opinionated toward correctness over breadth.
Guided practice
- Answer "revenue by city, paid orders only, top 5" with one
analysis.sqlcall; explain why you chose SQL overgroup_by. - Generate an HTML report with a summary section and a by-city table; open it in a browser.
- Run
analysis.profilethen at_test_indon two segments of the same column and interpret the result honestly.