PeaBox Lab › PeaLang › Learn › Chapter 29 › Lesson 1

Part V — The Modern Experience Layer · Chapter 29 · Lesson 1 of 2

Profiling, cleaning, joining and reshaping

analysis is a built-in namespace: functions over record lists for loading, cleaning, transforming, aggregating and exporting data. No notebooks and no external services are required.

Load and inspect

let df = analysis.read_csv_file("orders.csv")
print analysis.shape(df)          # {"rows": n, "columns": n}
print analysis.profile(df)        # missing values, distinct counts, min/max/mean per column

analysis.from_csv(text) parses CSV text you already have; analysis.read_csv_file(path) reads a file. profile returns a record with rows, columns and a fields map — the ten-minute first look you should do before any transformation.

Clean

Transform

let paid = analysis.query(df, "status", "==", "paid")
let by_city = analysis.group_by_multi(paid, ["city"], "amount", "sum")
let ranked = analysis.sort_by(by_city, "sum_amount", true)

analysis.query(data, column, op, value) filters with ==, !=, >, in, contains and friends; analysis.filter_rows(data, predicate) takes a function instead. analysis.group_by(data, column, value_column=None, agg="count") returns a map of key to count or aggregate (count, sum, mean, min, max); analysis.group_by_multi(data, group_columns, value_column=None, agg="count") returns one record per group and also accepts median. Aggregates are written as sum_amount, mean_amount and so on.

select, drop_columns, rename, add_column and assign shape columns; melt, transpose, pivot, pivot_wider and pivot_table reshape; join/merge and concat combine. Column-level aggregates such as mean_col, sum_col, median_col, mode and nunique sit alongside the grouping verbs.

Exploring

head / tail / sample / nlargest / nsmallest / unique / value_counts / top_values answer the usual questions in seconds. describe, corr_matrix and correlation surface relationships; quantile and histogram show the distribution shape.

Window operations

rolling_mean / rolling_std / expanding_mean / ewm_mean / pct_change / diff / shift / lag / lead / rank / cumsum — the time-series verbs from the records chapter. analysis.date_range(start, end) builds a date sequence; stats.calendar_features(values, parts=None) expands dates into numeric parts.

Export

analysis.write_csv_file("revenue-by-city.csv", ranked)
print analysis.to_markdown(analysis.profile(ranked))
print analysis.to_html(ranked)     # standalone HTML wrapper

analysis.to_csv(data) returns CSV text; analysis.write_csv_file(path, data) writes it to disk. The write_report_markdown(path, report), write_report_html(path, report) and write_report_json(path, report) helpers save finished artifacts.

Guided practice

← Previous Next →