pandas for TypeScript
tsb is a ground-up TypeScript implementation of the pandas data
manipulation library, with full API parity, strict types, and an interactive
playground for every feature.
📚 End-to-end pandas-style scenarios
Thirteen complete, real-world workflows running interactively in the browser — sales dashboards, stock returns, A/B tests, web analytics, league tables, and more.
📐 Project Foundation
Bun, TypeScript (strict), Biome linting, CI, Pages deployment, type system.
🔀 merge
SQL-style DataFrame joins. inner/left/right/outer, on/left_on/right_on, suffixes.
🔡 str accessor
Vectorised string operations. lower/upper/strip/pad/contains/replace/split/extract & predicates.
📅 dt accessor
Vectorised datetime operations. Calendar components, boolean boundaries, strftime, floor/ceil/round.
📊 describe
Summary statistics. count/mean/std/min/percentiles/max for numeric; count/unique/top/freq for categorical. Series.quantile().
📥 I/O
CSV I/O. readCsv / toCsv with dtype inference, NA handling, quoted fields, custom separators.
📥 JSON I/O
JSON I/O. readJson / toJson with five orient formats: records, split, index, columns, values.
📈 corr & cov
Pearson correlation & covariance. Series.corr(), DataFrame.corr(), DataFrame.cov(), dataFrameCorr(), dataFrameCov() with index alignment, null handling, and configurable ddof/minPeriods.
🪟 rolling
Sliding-window aggregations. Series.rolling() and DataFrame.rolling() with mean, sum, std, var, min, max, count, median, apply. Supports minPeriods and centered windows.
📈 expanding
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.
🏷️ cat accessor
Categorical operations. Series.cat with categories, codes, ordered, addCategories, removeCategories, renameCategories, setCategories, reorderCategories, valueCounts.
📉 ewm
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.
🔀 melt
Wide-to-long reshape. Unpivot columns into variable/value pairs with id_vars, value_vars, var_name, value_name.
🔄 pivot & pivotTable
Reshape with aggregation. pivot() for unique reshaping; pivotTable() for aggregation (mean/sum/count/min/max/first/last) with fill_value and dropna support.
📐 stack & unstack
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.
🏆 rank
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.
🔝 nlargest / nsmallest
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.
📈 cumulative operations
Compute running totals, products, maxima, and minima. cumsum(), cumprod(), cummax(), cummin() for Series and DataFrame with skipna support and axis=0/1.
✂️ element-wise ops
Element-wise transformations. clip(), seriesAbs(), seriesRound() for Series and DataFrame with min/max bounds, decimal precision, and axis support.
🔢 value_counts
Count unique values. valueCounts() for Series and dataFrameValueCounts() for DataFrame with normalize, sort, ascending, and dropna options.
🗂️ MultiIndex
Hierarchical indexing. MultiIndex for multi-level row and column labels with fromArrays, fromTuples, fromProduct, level access, and swapLevels.
📥 insertColumn / popColumn
Insert and remove DataFrame columns at precise positions. insertColumn(df, loc, col, values) inserts at integer position, popColumn(df, col) returns { series, df }. Also includes reorderColumns and moveColumn. Mirrors pandas.DataFrame.insert() and .pop().
✂️ cut / qcut
Bin continuous numeric data into discrete intervals. cut() uses fixed-width or explicit bin edges; qcut() uses quantile-based bins of equal population. Both return codes, labels, and bin edges. Mirrors pandas.cut and pandas.qcut.
📊 Rolling Extended Stats
Higher-order rolling window statistics: rollingSem (standard error of mean), rollingSkew (Fisher-Pearson skewness), rollingKurt (excess kurtosis), and rollingQuantile (arbitrary percentile with 5 interpolation methods). Mirrors pandas.Series.rolling().sem/skew/kurt/quantile().
🔧 Rolling Apply & Multi-Agg
Standalone custom rolling-window functions: rollingApply (custom fn per window), rollingAgg (multiple named aggregations → DataFrame), dataFrameRollingApply, dataFrameRollingAgg. Supports minPeriods, center, and raw mode. Mirrors pandas.Rolling.apply() and Rolling.agg().
🪟 Window Indexers
Custom window indexers for rolling computations: BaseIndexer (abstract base), FixedForwardWindowIndexer (forward-looking N-row window), VariableOffsetWindowIndexer (per-row variable depth), and applyIndexer() helper. Mirrors pandas.api.indexers.
🗺️ Series.map()
Map Series values using a function, Record/dict, another Series (index-label lookup), or ES6 Map. Missing keys produce null. Optional naAction: "ignore" passes NA values through unchanged. Mirrors pandas.Series.map().
⚙️ pd.options system
getOption · setOption · resetOption · describeOption · optionContext · options proxy. Full validator support and 20+ built-in options across display.*, mode.*, compute.* namespaces. Mirrors pandas.get_option / pandas.set_option.
🎭 where / mask
Element-wise conditional selection: seriesWhere / seriesMask and dataFrameWhere / dataFrameMask. Accepts boolean arrays, label-aligned boolean Series/DataFrame, or callables. Mirrors pandas.Series.where, pandas.DataFrame.where, and their .mask() inverses.
🔎 query / eval
Filter rows or evaluate expressions using a pandas-style expression string. queryDataFrame(df, "col > 5 and label in ['a', 'b']") and evalDataFrame(df, "price * qty"). Supports arithmetic, comparisons, logical operators, membership tests, backtick-quoted column names, and built-in functions (abs, round, isnull, lower, …). Mirrors pandas.DataFrame.query and pandas.DataFrame.eval.
🔍 isna / notna
Module-level missing-value detection: isna, notna, isnull, notnull work on scalars, arrays, Series, and DataFrames. Plus standalone fillna, dropna, countna, and countValid. Mirrors pandas.isna, pandas.notna, pandas.isnull, pandas.notnull.
🏷️ attrs — User Metadata
Attach arbitrary key→value metadata to any Series or DataFrame via a WeakMap registry. Provides getAttrs, setAttrs, updateAttrs, copyAttrs, withAttrs, mergeAttrs, clearAttrs, getAttr, setAttr, deleteAttr, attrsCount, attrsKeys. Mirrors pandas.DataFrame.attrs / pandas.Series.attrs.
🔤 string_ops — Standalone String Ops
Module-level string utilities: strNormalize (Unicode NFC/NFD/NFKC/NFKD), strGetDummies (one-hot DataFrame), strExtractAll (all regex matches), strRemovePrefix, strRemoveSuffix, strTranslate (char-level substitution), strCharWidth (CJK-aware display width), strByteLength. Works on Series, arrays, or scalars.
🔤 string_ops_extended — Extended String Ops
Advanced string utilities: strSplitExpand (split → DataFrame columns), strExtractGroups (regex capture groups → DataFrame), strPartition / strRPartition (split into before/sep/after), strMultiReplace (batch replacements), strIndent / strDedent (line-level indentation). Works on Series, arrays, or scalars.
🔗 pipe_apply — Pipeline & Apply Utilities
Standalone equivalents of pandas' pipe() / apply() / applymap(): pipe (variadic type-safe pipeline), seriesApply (element-wise with label/pos context), seriesTransform, dataFrameApply (axis 0/1), dataFrameApplyMap (cell-wise), dataFrameTransform (column-wise), dataFrameTransformRows (row-wise).
🔢 numeric_extended — Numeric Utilities
numpy/scipy-style numeric utilities: digitize (bin values), histogram (frequency counts with density option), linspace / arange (number sequences), percentileOfScore (percentile rank of a score), zscore (z-score standardisation), minMaxNormalize (scale to [0,1] or custom range), coefficientOfVariation (std/mean). Series-aware variants included.
🏷️ categorical_ops — Categorical Utilities
Standalone categorical helpers: catFromCodes (from integer codes), set operations (catUnionCategories, catIntersectCategories, catDiffCategories, catEqualCategories), catSortByFreq, catToOrdinal, catFreqTable, catCrossTab, catRecode.
🔢 format_ops — Number Formatting
Number-formatting helpers for Series and DataFrame. Scalar formatters: formatFloat, formatPercent, formatScientific, formatEngineering, formatThousands, formatCurrency, formatCompact. Formatter factories: makeFloatFormatter, makePercentFormatter, makeCurrencyFormatter. Apply to collections: applySeriesFormatter, applyDataFrameFormatter. Render to string: seriesToString, dataFrameToString.
📗 Excel I/O
XLSX file reading. readExcel() parses Excel files from a Uint8Array/ArrayBuffer — ZIP+XML parsing from scratch, shared strings, number/string/boolean cells, sheet selection, header, indexCol, skipRows, nrows.
🔍 missing-value ops
Detect and fill missing values. isna(), notna(), isnull(), notnull() for scalars/Series/DataFrame. ffillSeries(), bfillSeries(), dataFrameFfill(), dataFrameBfill() with optional limit and axis support.
📈 diff / shift
Discrete difference and value shifting for Series and DataFrame. diff computes element-wise differences; shift lags or leads values by a number of periods. Essential for time-series analysis.
🔢 NaN-Ignoring Aggregates
Top-level nan-ignoring aggregate functions: nansum, nanmean, nanmedian, nanstd, nanvar, nanmin, nanmax, nanprod, nancount. Mirrors numpy.nan* functions. Works on arrays and Series.
⏱️ toTimedelta
Convert scalars, arrays, or Series to Timedelta objects. Accepts pandas-style strings, ISO 8601, human-readable, and numeric values. Timedelta class with arithmetic: add/subtract/scale/abs/lt/gt/eq.
⏳ timedelta_range
Generate fixed-frequency TimedeltaIndex sequences. Supports start/end/periods/freq combinations, multiplier prefixes (e.g. "2H", "30min"), linear spacing, and closed endpoint control.
🔍 strFindall & toJsonDenormalize
strFindall/strFindallCount/strFindFirst/strFindallExpand — regex match extraction per element (mirrors pandas str.findall). toJsonDenormalize/toJsonRecords/toJsonSplit/toJsonIndex — serialize DataFrames to nested or flat JSON.
📊 cutBinsToFrame
Convert cut/qcut BinResult into a tidy summary DataFrame. cutBinsToFrame returns bin labels, edges, counts, and frequencies. cutBinCounts returns a label→count dict. binEdges returns an edges-only DataFrame.
✂️ xs — Cross-Section
xsDataFrame / xsSeries — select rows or columns by label (mirrors pandas .xs()). Supports flat and MultiIndex, axis selection, level targeting, and dropLevel control.
↔️ between — Range Check
seriesBetween — element-wise range check returning a boolean Series. Mirrors pandas Series.between(). Supports inclusive="both"|"left"|"right"|"neither".
🔄 update — In-place Update
seriesUpdate / dataFrameUpdate — update values from another object using label alignment. Non-NA values in other overwrite self. Mirrors pandas DataFrame.update().
🔽 filter — Filter Labels
filterDataFrame / filterSeries — filter rows or columns by label using items list, substring (like), or regex pattern. Mirrors pandas DataFrame.filter().
🔀 combine — Element-wise Combination
combineSeries / combineDataFrame — combine two objects element-wise with a caller-supplied binary function. Result index is the union of both indices. Mirrors pandas Series.combine() / DataFrame.combine().
✅ keepTrue / keepFalse / filterBy — Boolean Indexing
keepTrue / keepFalse / filterBy — boolean-mask selection helpers for Series and DataFrames. Mirrors pandas boolean indexing (series[mask], df[mask]).
🔢 scalar_extract — squeeze / item / bool / first_valid_index
squeezeSeries / squeezeDataFrame / itemSeries / boolSeries / boolDataFrame / firstValidIndex / lastValidIndex — scalar-extraction helpers for Series and DataFrames. Mirrors pandas Series.squeeze(), item(), bool(), first_valid_index(), last_valid_index().
📊 corrWith / autoCorr — Pairwise Correlation & Autocorrelation
corrWith / autoCorr — compute pairwise Pearson correlations between a DataFrame and a Series or DataFrame, and compute lag-N autocorrelation for a Series. Mirrors pandas DataFrame.corrwith() and Series.autocorr().
🔗 join / joinAll / crossJoin — Label-Based Joins
join / joinAll / crossJoin — join DataFrames by index labels or a key column. join() defaults to left-join-on-index, joinAll() chains multiple joins, crossJoin() produces the Cartesian product. Mirrors pandas DataFrame.join().
⏱️ merge_asof — Ordered Nearest-Key Join
mergeAsof — ordered left-join on the nearest key (backward/forward/nearest). Ideal for time-series: match trades to most recent quotes. Supports by-group matching, tolerance, allow_exact_matches, and custom suffixes. Mirrors pandas.merge_asof().
📋 merge_ordered — Ordered Fill Merge
mergeOrdered — ordered outer/inner/left/right merge sorted by key column(s). Supports fill_method: "ffill" to forward-fill null gaps, left_by/right_by for group-wise ordered merging, left_on/right_on for different key names, and suffix handling. Mirrors pandas.merge_ordered().
📅 resample — Time-Based Resampling
resampleSeries / resampleDataFrame — time-based groupby aggregation. Supports S/T/H/D/W/MS/ME/QS/QE/YS/YE frequencies, aggregations (sum, mean, min, max, count, first, last, std, var, size, ohlc), per-column agg specs, and automatic empty-bin filling. Mirrors pandas.DataFrame.resample().
🔍 infer_objects / convert_dtypes — Dtype Inference
inferObjectsSeries / inferObjectsDataFrame / convertDtypesSeries / convertDtypesDataFrame — promote object-typed Series to better dtypes and parse string columns as numbers. Mirrors pandas infer_objects() and convert_dtypes().
🧪 testing — Assertion Utilities
assertSeriesEqual / assertFrameEqual / assertIndexEqual — rich assertion helpers for use in test suites. Numeric tolerance, checkLike column-order mode, dtype checks, AssertionError with detailed diff messages. Mirrors pandas.testing.
🎨 Styler — DataFrame Style API
dataFrameStyle(df) · highlightMax / highlightMin / highlightNull / highlightBetween · backgroundGradient / textGradient · barChart · format / formatIndex · apply / applymap / map · setCaption / setTableStyles / hide · toHtml / toLatex. Mirrors pandas.DataFrame.style (Styler).
🔑 hashPandasObject — FNV-1a Hashing
hashPandasObject(s) · hashPandasObject(df) · index option. Mirrors pandas.util.hash_pandas_object. FNV-1a 64-bit per element or row.
🗃️ pdArray — pd.array() Factory
pdArray(data, dtype?) — create typed arrays from any iterable. Dtype inference for int64/float64/bool/string/datetime. Mirrors pandas.array().
📋 Table Formatters — to_markdown / to_latex
toMarkdown() and toLaTeX() — render DataFrames and Series as Markdown tables or LaTeX tabular environments. Mirrors pandas.DataFrame.to_markdown() and to_latex().
🌐 readHtml — pd.read_html()
readHtml(html, opts?) — parse HTML tables into DataFrames. Header detection, NA handling, numeric coercion, thousands/decimal separators, indexCol, match filter. Mirrors pandas.read_html().