deepbox/dataframe
IO, Styling & Plotting
Read and write CSV, JSON, Parquet and Excel data, style tables as HTML or ANSI text, and plot columns through df.plot.
- IO
- Styling
Overview
- Parquet and Excel work on bytes, not paths.
df.toParquet()anddf.toXlsx()return aUint8Array, andDataFrame.fromParquet(bytes)andDataFrame.fromXlsx(bytes)read one. The standalonewriteParquet(columns, rows),readParquet(bytes),writeXlsxandreadXlsxdo the same with plain row objects. Write the bytes to disk withnode:fs. - CSV and JSON are
DataFramemethods:fromCsvString,readCsv,toCsvString,toCsv,fromJsonString,readJson,toJsonStringandtoJson. The file variants are asynchronous and need Node.js. readParquetreads flat schemas with plain and dictionary encodings, in uncompressed, Snappy or gzip (Node.js only) form, which covers the defaults of pyarrow and pandas. Nested columns, DECIMAL, INT96, delta encodings, ZSTD, LZ4 and Brotli throw instead of returning wrong data. Invalid buffers throwDataValidationError.- Excel date cells come back as serial numbers, and
writeXlsxwritesDatevalues as ISO text. Neither format stores the row index, so reading gives a default 0 to n-1 index. df.stylebuilds conditional formatting and renders it withtoHTML()ortoANSI(). Thedf.plotmethods (line,bar,hist,scatter,box,pie,area) return aFigurethat you render or save.
ParquetReadOptions
typeOptions for reading a Parquet file.
readonly columns?: readonly string[]Columns to read, returned in the order given.
ParquetReadResult
typeResult of readParquet: the column names and one record per row.
columns: string[]data: Record<string, unknown>[]
ParquetWriteOptions
typeOptions for writing a Parquet file.
readonly createdBy?: stringCreated-by string.
XlsxCell
typeA cell value as returned by readXlsx.
type XlsxCell = string | number | boolean | null;XlsxReadOptions
typeOptions for reading an XLSX file.
readonly sheet?: string | numberSheet to read: a sheet name, or a 0-based position in workbook order.
readonly header?: booleanWhether the first row contains headers.
readonly maxEntryBytes?: numberMaximum decompressed size per zip entry in bytes (guards against decompression bombs in untrusted files).
readonly maxCells?: numberMaximum number of cells (rows times columns of the used range) the result may hold.
XlsxReadResult
typeResult of readXlsx: the header names and one record per row.
columns: string[]data: Record<string, XlsxCell>[]
XlsxWriteOptions
typeOptions for writing an XLSX file.
readonly sheetName?: stringSheet name.
PlotBaseOptions
typeOptions shared by every plot method.
readonly figsize?: readonly [ number, number ]Figure size as
[width, height]in pixels (default:[640, 480]).readonly title?: stringTitle drawn above the axes.
CellStyle
typeA single cell style rule.
readonly color?: stringreadonly backgroundColor?: stringreadonly fontWeight?: stringreadonly fontStyle?: stringreadonly textAlign?: string
StyleFunction
typeA formatting function that receives a cell value and returns a CSS-like style object.
type StyleFunction = (value: unknown, row: number, col: number) => CellStyle;PlotAccessor
Plotting accessor for DataFrame.
Access via df.plot.line(), df.plot.bar(), etc. Every method returns the Figure, which can be rendered with renderSVG() or saved. Columns that are named in the options must exist; otherwise an InvalidParameterError lists the available columns. When no columns are named, only numeric columns are used. Missing values (null, undefined, NaN) are skipped by the underlying plots.
import { DataFrame } from 'deepbox/dataframe'; const df = new DataFrame({ x: [1, 2, 3], y: [4, 5, 6] });const fig = df.plot.line({ x: 'x', y: 'y' });Members (8)
line(options?: PlotBaseOptions & { readonly x?: string; readonly y?: string | readonly string[]; }): FigureLine plot.
bar(options?: PlotBaseOptions & { readonly x?: string; readonly y?: string | readonly string[]; }): FigureBar plot.
barh(options?: PlotBaseOptions & { readonly x?: string; readonly y?: string; }): FigureHorizontal bar plot.
hist(options?: PlotBaseOptions & { readonly column?: string | readonly string[]; readonly bins?: number; }): FigureHistogram.
scatter(options: PlotBaseOptions & { readonly x: string; readonly y: string; }): FigureScatter plot.
box(options?: PlotBaseOptions & { readonly column?: string | readonly string[]; }): FigureBox plot.
pie(options: PlotBaseOptions & { readonly y: string; readonly labels?: string; }): FigurePie chart from a single column.
area(options?: PlotBaseOptions & { readonly x?: string; readonly y?: string | readonly string[]; }): FigureArea plot (filled line plot).
StyleAccessor
Style accessor for DataFrame.
Access via df.style. Allows chaining conditional formatting rules and rendering to HTML or plain-text tables. Rules that look at a whole column (highlightMax, backgroundGradient, ...) read the DataFrame when they are added. Rules apply in the order they were added, and a later rule overrides an earlier one for the same CSS property.
import { DataFrame } from 'deepbox/dataframe'; const df = new DataFrame({ a: [1, 2, 3], b: [4, 5, 6] });const html = df.style .highlightMax({ color: 'green' }) .highlightMin({ color: 'red' }) .toHTML();Members (15)
setCaption(caption: string): thisSet a caption for the styled table.
applymap(fn: StyleFunction): thisApply a generic style function to all cells.
map(fn: StyleFunction): thisAlias of StyleAccessor.applymap, the name pandas uses since 2.1.
highlightMax(style?: CellStyle): thisHighlight the maximum value in each column.
highlight_max(style?: CellStyle): thisdeprecatedSame as StyleAccessor.highlightMax.
highlightMin(style?: CellStyle): thisHighlight the minimum value in each column.
highlight_min(style?: CellStyle): thisdeprecatedSame as StyleAccessor.highlightMin.
highlightNull(style?: CellStyle): thisHighlight missing values: null, undefined and NaN.
highlight_null(style?: CellStyle): thisdeprecatedSame as StyleAccessor.highlightNull.
backgroundGradient(low?: string, high?: string): thisApply a color gradient (background) based on numeric values.
background_gradient(low?: string, high?: string): thisdeprecatedSame as StyleAccessor.backgroundGradient.
bar(color?: string): thisDraw an inline bar in each numeric cell.
format(column: string, formatter: (value: unknown) => string): thisSet a formatter for a specific column.
toHTML(): stringRender the styled DataFrame as an HTML table string.
toANSI(): stringRender a plain-text table with ANSI escape codes.
readParquet
function readParquet(buffer: Uint8Array, options?: ParquetReadOptions): ParquetReadResult;Read column data from a Parquet buffer.
Details
Supports flat schemas with any number of row groups and data pages (v1 and v2), PLAIN / dictionary / RLE-boolean encodings and UNCOMPRESSED, SNAPPY or GZIP (Node.js only) compression, which covers the defaults of pyarrow and pandas. Anything outside that subset (nested columns, DECIMAL, INT96, delta encodings, ZSTD/LZ4/Brotli) throws a descriptive error instead of returning wrong data.
Value mapping: BOOLEAN to boolean, INT32/FLOAT/DOUBLE to number, INT64 to number (or bigint when the value is beyond +/-2^53), strings to string, unannotated BYTE_ARRAY to Uint8Array, DATE and TIMESTAMP columns to Date (nanoseconds are truncated to milliseconds), unsigned integers to non-negative values, nulls to null.
Parameters
bufferUint8Array- The raw .parquet file as a Uint8Array
optionsoptionalParquetReadOptions- Read options (
columnsselects and orders a subset)
Returns
ParquetReadResultParsed data with columns and rows
Throws
DataValidationErrorIf the buffer is not a valid or supported Parquet fileInvalidParameterErrorIfoptions.columnsnames a column the file does not have
readXlsx
function readXlsx(buffer: Uint8Array, options?: XlsxReadOptions): XlsxReadResult;Read cell data from an XLSX buffer.
Details
Returns an object with columns (header names) and data (array of objects mapping column names to values).
Empty cells are null, formula cells give their cached result (formula errors become null), and numeric cells are numbers (dates are Excel serial numbers). Rows keep their sheet positions, so blank rows inside the data stay as rows of null; blank rows before the data are dropped. Blank rows after the data are dropped too, except plain empty rows inside the sheet's declared dimension, which is how writeXlsx stores all-null rows. Trailing empty columns are dropped. Blank or missing header cells are named Column<i> and repeated headers are suffixed .1, .2, ... like pandas.
Parameters
bufferUint8Array- The raw .xlsx file as a Uint8Array
optionsoptionalXlsxReadOptions- Read options
Returns
XlsxReadResultParsed spreadsheet data
Throws
DataValidationErrorIf the buffer is not a valid .xlsx file, the sheet does not exist, an XML element is not closed, or the used range exceedsmaxCellsInvalidParameterErrorIfmaxEntryBytesormaxCellsis not a positive number
writeParquet
function writeParquet(columns: readonly string[], data: readonly Record<string, unknown>[], options?: ParquetWriteOptions): Uint8Array;Write DataFrame-like data to a Parquet buffer.
Details
Column types are inferred from every value of the column: booleans become BOOLEAN, Dates become TIMESTAMP_MILLIS, integers become INT32 (or INT64 when any value exceeds the 32-bit range or is a bigint), other numbers become DOUBLE, and everything else (strings, mixed columns) is stored as UTF-8 text. Invalid dates are written as nulls.
Columns containing null/undefined are written as OPTIONAL with RLE definition levels, so nulls survive the round-trip (also when read by external tools such as pyarrow/pandas). NaN is a regular DOUBLE value, not a null.
Parameters
columnsreadonly string[]- Column names (must be unique)
datareadonly Record<string, unknown>[]- Array of row objects
optionsoptionalParquetWriteOptions- Write options
Returns
Uint8ArrayUint8Array containing the .parquet file
Throws
DataValidationErrorIf column names repeat, a row is not an object, abigintexceeds the INT64 range, or a column chunk is larger than 2 GiB
writeXlsx
function writeXlsx(columns: readonly string[], data: readonly Record<string, unknown>[], options?: XlsxWriteOptions): Uint8Array;Write DataFrame-like data to an XLSX buffer.
Value mapping: numbers become numeric cells (NaN and null/undefined become empty cells, Infinity/-Infinity are written as the text "inf"/"-inf" since Excel has no such numbers), booleans become boolean cells, safe-integer bigints become numbers, Dates become ISO 8601 text (invalid dates are empty), and everything else is written as text.
Parameters
columnsreadonly string[]- Column names (header row); must be unique
datareadonly Record<string, unknown>[]- Array of row objects (column name to value)
optionsoptionalXlsxWriteOptions- Write options
Returns
Uint8ArrayUint8Array containing the .xlsx file
Throws
DataValidationErrorIf column names repeat, exceed Excel's sheet limits, or a text cell is longer than 32767 charactersInvalidParameterErrorIfsheetNameis not a valid Excel sheet name
import { DataFrame } from "deepbox/dataframe"; const df = new DataFrame({ name: ["A", "B", "C"], score: [88, 74, 95],}); const xlsx = df.toXlsx({ sheetName: "Scores" });const parquet = df.toParquet();console.log(DataFrame.fromXlsx(xlsx).toString());console.log(DataFrame.fromParquet(parquet, { columns: ["score"] }).toString());console.log(df.toCsvString()); const html = df.style.highlightMax().toHTML();const figure = df.plot.bar({ x: "name", y: "score" });console.log(html.length > 0, figure.renderSVG().svg.length > 0);Found a mistake? Open an issue.