Parse fixed-width formatted text into a
DataFrame with readFwf().
Mirrors pandas
read_fwf() — column boundaries are inferred from whitespace patterns
automatically, or provided explicitly via colspecs / widths.
Edit any code block below and press ▶ Run
(or Ctrl+Enter) to execute it live in your browser.
When colspecs is omitted (default "infer"),
readFwf() scans the data rows and identifies separator positions —
character columns where every row contains a space. This mirrors
pandas.read_fwf(colspecs='infer').
Provide colspecs — an array of [start, end) character
index pairs — for precise control over column boundaries. Useful when separator
positions vary between rows.
Alternatively, pass widths — an array of integers — to define
consecutive column widths. This produces [0,w0], [w0,w0+w1], …
colspecs internally.
Standard NA strings (NA, NaN, null, …) are
recognised automatically. Add custom NA strings with naValues.
Force a column's dtype with the dtype option.
Promote a column to the row index with indexCol.
Limit rows with nRows and skip leading data rows with
skipRows.
Fixed-width format is common in government datasets, legacy mainframe exports, and statistical software output. Here is a Census-style table.
Parse a fixed-width formatted text string into a DataFrame.
Equivalent to pandas.read_fwf().
readFwf(text: string, options?: ReadFwfOptions): DataFrame
type ColSpec = readonly [number, number]; // [start, end) character indices
interface ReadFwfOptions {
colspecs?: readonly ColSpec[] | "infer"; // column boundaries (default: "infer")
widths?: readonly number[]; // column widths (alternative to colspecs)
inferNrows?: number; // rows to sample for inference (default: 100)
header?: number | null; // header row index (default: 0)
names?: readonly string[]; // explicit column names
indexCol?: string | number | null; // column to use as row index
dtype?: Record<string, DtypeName>; // force dtype for named columns
naValues?: readonly string[]; // extra NA string values
skipRows?: number; // data rows to skip after header
nRows?: number; // maximum data rows to read
}