From 0ad6935d800a2b3e2b12afef3dff910939b39721 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Apr 2026 13:55:44 +0000 Subject: [PATCH 01/17] Initial plan From fa0422b05191f57d988e6d2eab78b66e97b75529 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Apr 2026 14:04:18 +0000 Subject: [PATCH 02/17] Rewrite value_counts.html to use interactive playground format Convert from static code blocks to the standard interactive playground template with editable textareas, run/reset buttons, loading overlay, dark theme, and playground-runtime.js integration. All 6 code examples are self-contained with proper imports and console.log() output. The API reference section is kept as a non-interactive reference block. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com> --- playground/index.html | 102 ++++---- playground/value_counts.html | 440 +++++++++++++++++++++++++++-------- 2 files changed, 395 insertions(+), 147 deletions(-) diff --git a/playground/index.html b/playground/index.html index 73ab3f0e..48bfbcb9 100644 --- a/playground/index.html +++ b/playground/index.html @@ -135,133 +135,133 @@
1-D labeled array — Interactive Playground. The core building block of tsb data structures.
+1-D labeled array. The core building block of tsb data structures.
2-D labeled table — interactive tutorial. Column-oriented storage, full pandas API.
+2-D labeled table. Column-oriented storage, full pandas API.
Immutable labeled axis — Interactive Playground, RangeIndex.
+Immutable labeled axis, RangeIndex.
Rich dtype system — Interactive Playground. int/float/bool/string/datetime/category.
+Rich dtype system. int/float/bool/string/datetime/category.
Split-apply-combine — interactive tutorial. groupby, agg, transform, apply, filter.
+Split-apply-combine. groupby, agg, transform, apply, filter.
Combine Series and DataFrames — interactive tutorial. axis=0/1, outer/inner join, ignoreIndex.
+Combine Series and DataFrames. axis=0/1, outer/inner join, ignoreIndex.
SQL-style DataFrame joins — interactive tutorial. inner/left/right/outer, on/left_on/right_on, suffixes.
+SQL-style DataFrame joins. inner/left/right/outer, on/left_on/right_on, suffixes.
Vectorised string operations — interactive tutorial. lower/upper/strip/pad/contains/replace/split/extract & predicates.
+Vectorised string operations. lower/upper/strip/pad/contains/replace/split/extract & predicates.
Vectorised datetime operations — interactive tutorial. Calendar components, boolean boundaries, strftime, floor/ceil/round.
+Vectorised datetime operations. Calendar components, boolean boundaries, strftime, floor/ceil/round.
Summary statistics — interactive tutorial. count/mean/std/min/percentiles/max for numeric; count/unique/top/freq for categorical. Series.quantile().
+Summary statistics. count/mean/std/min/percentiles/max for numeric; count/unique/top/freq for categorical. Series.quantile().
CSV I/O — interactive tutorial. readCsv / toCsv with dtype inference, NA handling, quoted fields, custom separators.
+CSV I/O. readCsv / toCsv with dtype inference, NA handling, quoted fields, custom separators.
JSON I/O — interactive tutorial. readJson / toJson with five orient formats: records, split, index, columns, values.
+JSON I/O. readJson / toJson with five orient formats: records, split, index, columns, values.
Pearson correlation & covariance — interactive tutorial. Series.corr(), DataFrame.corr(), DataFrame.cov(), dataFrameCorr(), dataFrameCov() with index alignment, null handling, and configurable ddof/minPeriods.
+Pearson correlation & covariance. Series.corr(), DataFrame.corr(), DataFrame.cov(), dataFrameCorr(), dataFrameCov() with index alignment, null handling, and configurable ddof/minPeriods.
Sliding-window aggregations — interactive tutorial. Series.rolling() and DataFrame.rolling() with mean, sum, std, var, min, max, count, median, apply. Supports minPeriods and centered windows.
+Sliding-window aggregations. Series.rolling() and DataFrame.rolling() with mean, sum, std, var, min, max, count, median, apply. Supports minPeriods and centered windows.
Growing-window aggregations — Series.expanding() and DataFrame.expanding() with mean, sum, std, var, min, max, count, median, apply. Window grows from start to current position.
+Growing-window aggregations. Series.expanding() and DataFrame.expanding() with mean, sum, std, var, min, max, count, median, apply. Window grows from start to current position.
Categorical operations — interactive tutorial. Series.cat with categories, codes, ordered, addCategories, removeCategories, renameCategories, setCategories, reorderCategories, valueCounts.
+Categorical operations. Series.cat with categories, codes, ordered, addCategories, removeCategories, renameCategories, setCategories, reorderCategories, valueCounts.
Exponentially Weighted Moving aggregations — interactive tutorial. Series.ewm() and DataFrame.ewm() with mean, std, var, cov, corr, apply. Decay via span, com, halflife, or alpha. Supports adjust and ignoreNa.
+Exponentially Weighted Moving aggregations. Series.ewm() and DataFrame.ewm() with mean, std, var, cov, corr, apply. Decay via span, com, halflife, or alpha. Supports adjust and ignoreNa.
Wide-to-long reshape — interactive tutorial. Unpivot columns into variable/value pairs with id_vars, value_vars, var_name, value_name.
+Wide-to-long reshape. Unpivot columns into variable/value pairs with id_vars, value_vars, var_name, value_name.
Reshape with aggregation — interactive tutorial. pivot() for unique reshaping; pivotTable() for aggregation (mean/sum/count/min/max/first/last) with fill_value and dropna support.
+Reshape with aggregation. pivot() for unique reshaping; pivotTable() for aggregation (mean/sum/count/min/max/first/last) with fill_value and dropna support.
Pivot column labels to/from row index — interactive tutorial. stack() rotates columns into a compound-index Series; unstack() recovers the DataFrame. Custom sep, dropna, and fill_value support.
+Pivot column labels to/from row index. stack() rotates columns into a compound-index Series; unstack() recovers the DataFrame. Custom sep, dropna, and fill_value support.
Assign numerical ranks to values — interactive tutorial. rankSeries() and rankDataFrame() with tie methods (average/min/max/first/dense), NaN handling (keep/top/bottom), percentage ranks, and axis support.
+Assign numerical ranks to values. rankSeries() and rankDataFrame() with tie methods (average/min/max/first/dense), NaN handling (keep/top/bottom), percentage ranks, and axis support.
Return the n largest or smallest values — interactive tutorial. nlargestSeries(), nsmallestSeries(), nlargestDataFrame(), nsmallestDataFrame() with keep='first'/'last'/'all' tie-handling, NaN exclusion, and multi-column DataFrame sorting.
+Return the n largest or smallest values. nlargestSeries(), nsmallestSeries(), nlargestDataFrame(), nsmallestDataFrame() with keep='first'/'last'/'all' tie-handling, NaN exclusion, and multi-column DataFrame sorting.
Compute running totals, products, maxima, and minima — interactive tutorial. cumsum(), cumprod(), cummax(), cummin() for Series and DataFrame with skipna support and axis=0/1.
+Compute running totals, products, maxima, and minima. cumsum(), cumprod(), cummax(), cummin() for Series and DataFrame with skipna support and axis=0/1.
Element-wise transformations — interactive tutorial. clip(), seriesAbs(), seriesRound() for Series and DataFrame with min/max bounds, decimal precision, and axis support.
+Element-wise transformations. clip(), seriesAbs(), seriesRound() for Series and DataFrame with min/max bounds, decimal precision, and axis support.
Count unique values — interactive tutorial. valueCounts() for Series and dataFrameValueCounts() for DataFrame with normalize, sort, ascending, and dropna options.
+Count unique values. valueCounts() for Series and dataFrameValueCounts() for DataFrame with normalize, sort, ascending, and dropna options.
Hierarchical indexing — interactive tutorial. MultiIndex for multi-level row and column labels with fromArrays, fromTuples, fromProduct, level access, and swapLevels.
+Hierarchical indexing. MultiIndex for multi-level row and column labels with fromArrays, fromTuples, fromProduct, level access, and swapLevels.
value_counts
- Count unique values in a Series or unique row combinations in a
- DataFrame. Mirrors
- pandas.Series.value_counts()
- and
- pandas.DataFrame.value_counts().
-
Count unique values in a Series or unique row
+ combinations in a DataFrame. Mirrors
+ pandas.Series.value_counts() and
+ pandas.DataFrame.value_counts().
+ Edit any code block below and press ▶ Run
+ (or Ctrl+Enter) to execute it live in your browser.
+
import { Series } from "tsb";
-import { valueCounts } from "tsb";
+ Create a Series and count how often each unique value appears. Results are sorted
+ descending by frequency by default.
+
+
+ TypeScript
+
+
+
+
+
+
+ Click ▶ Run to execute
+ Ctrl+Enter to run · Tab to indent
+
+ const pct = valueCounts(s, { normalize: true });
-// values → [0.5, 0.333…, 0.167…] (must sum to 1)
- Pass normalize: true to get relative frequencies that sum to 1
+ instead of raw counts.
// Ascending order (least frequent first)
+ Control sorting: ascending: true for least-frequent first, or
+ sort: false to preserve insertion order.
+
+
+ TypeScript
+
+
+
+
+
+
+ Click ▶ Run to execute
+ Ctrl+Enter to run · Tab to indent
+
+ const sWithNull = new Series({ data: ["a", null, "b", null, "a"] });
+ By default nulls are excluded (dropna: true). Set
+ dropna: false to include them in the count.
+
+
+ TypeScript
+
+
+
+
+
+
+ Click ▶ Run to execute
+ Ctrl+Enter to run · Tab to indent
+
+ import { DataFrame } from "tsb";
-import { dataFrameValueCounts } from "tsb";
+ Count unique row combinations across all columns. Each unique
+ (city, temp) pair becomes an index label.
+
+
+ TypeScript
+
+
+
+
+
+
+ Click ▶ Run to execute
+ Ctrl+Enter to run · Tab to indent
+
+ // Restrict to a subset of columns
-const vc2 = dataFrameValueCounts(df, { subset: ["city"] });
-// Only counts by city: NYC=3, LA=1
- Restrict counting to a subset of columns with the subset option.
The result Series is indexed by the unique values (or composite
+ "v1|v2|…" strings for DataFrames). Use .index.values and
+ .values to inspect the labels and counts respectively.
// Series
valueCounts(series, {
- normalize?: boolean, // default false — return proportions instead of counts
+ normalize?: boolean, // default false — return proportions
sort?: boolean, // default true — sort by frequency
- ascending?: boolean, // default false — highest count first when sort=true
+ ascending?: boolean, // default false — highest count first
dropna?: boolean, // default true — exclude missing values
}): Series<number>
@@ -132,13 +379,14 @@ 7 · API reference
ascending?: boolean,
dropna?: boolean,
}): Series<number>
+ "v1|v2|…" strings for DataFrames). Use .index.values and
- .values to inspect the labels and counts respectively.
- blocks to
interactive with editable