HTML table extraction from SEC filings.
Extracts <table> elements from filing HTML and converts them to tech.ml.dataset objects. Handles iXBRL inline-tagged content, colspan layouts (Workiva-style grids where one value sits in a 2- or 3-column span), currency/percent fragments split into their own cells, and mixed numeric/string columns.
Usage: (require '[edgar.tables :as tables]) (tables/extract-tables filing) ; => seq of datasets (tables/extract-tables filing :n 0) ; => first table as dataset (tables/extract-tables filing :min-rows 5) ; => only tables with >=5 data rows
HTML table extraction from SEC filings. Extracts <table> elements from filing HTML and converts them to tech.ml.dataset objects. Handles iXBRL inline-tagged content, colspan layouts (Workiva-style grids where one value sits in a 2- or 3-column span), currency/percent fragments split into their own cells, and mixed numeric/string columns. Usage: (require '[edgar.tables :as tables]) (tables/extract-tables filing) ; => seq of datasets (tables/extract-tables filing :n 0) ; => first table as dataset (tables/extract-tables filing :min-rows 5) ; => only tables with >=5 data rows
(extract-tables filing
&
{:keys [n min-rows min-cols] :or {min-rows 2 min-cols 2}})Extract HTML tables from a filing as a seq of tech.ml.dataset objects.
filing — a filing map (from e/filing, e/filings, e/filing-by-accession, etc.) Options: :n — return only the nth table (0-indexed) among the tables that pass the filters; returns a single dataset or nil :min-rows — only return tables with at least this many data rows (default 2; :min-rows 1 also keeps single-row tables, and a table always needs at least one data row) :min-cols — only return tables with at least this many columns (default 2)
Returns a seq of datasets (or a single dataset when :n is used). Each dataset is named "table-N" where N is the original index in the HTML. Columns are in the table's left-to-right order.
Cleanup applied to every table:
Tables that appear to be layout/navigation (no data row with at least two non-blank cells) are automatically filtered out.
Returns nil (for :n) or an empty seq when the filing has no HTML content or the HTML contains no tables.
Example: (require '[edgar.tables :as tables] '[edgar.api :as e]) (def f (e/filing "AAPL" :form "10-K"))
;; All data tables (tables/extract-tables f)
;; Only tables with at least 5 data rows (tables/extract-tables f :min-rows 5)
;; First table (tables/extract-tables f :n 0)
;; Third table (tables/extract-tables f :n 2)
Extract HTML tables from a filing as a seq of tech.ml.dataset objects.
filing — a filing map (from e/filing, e/filings, e/filing-by-accession, etc.)
Options:
:n — return only the nth table (0-indexed) among the tables that
pass the filters; returns a single dataset or nil
:min-rows — only return tables with at least this many data rows
(default 2; :min-rows 1 also keeps single-row tables, and a
table always needs at least one data row)
:min-cols — only return tables with at least this many columns (default 2)
Returns a seq of datasets (or a single dataset when :n is used).
Each dataset is named "table-N" where N is the original index in the HTML.
Columns are in the table's left-to-right order.
Cleanup applied to every table:
- the header is the first row with at least two non-blank cells
- colspan cells hold their value once; each data cell goes to the
column of the header cell spanning it, and columns blank in every
row are dropped
- "$", "(", ")" and "%" in cells of their own are merged into the
adjacent number
- a column whose cells are all numbers, blanks or dash placeholders
("—", "–", "-") is numeric: commas, currency symbols and "%"
are stripped, parentheses mean negative, blanks and dashes are nil
Tables that appear to be layout/navigation (no data row with at least two
non-blank cells) are automatically filtered out.
Returns nil (for :n) or an empty seq when the filing has no HTML content
or the HTML contains no tables.
Example:
(require '[edgar.tables :as tables]
'[edgar.api :as e])
(def f (e/filing "AAPL" :form "10-K"))
;; All data tables
(tables/extract-tables f)
;; Only tables with at least 5 data rows
(tables/extract-tables f :min-rows 5)
;; First table
(tables/extract-tables f :n 0)
;; Third table
(tables/extract-tables f :n 2)(html-content? s)True when the string looks like an HTML document: it has a doctype,
<html> or <body> tag. A bare <table> is not enough — pre-2001 SGML plain-text filings mark their tables with <TABLE> too.
True when the string looks like an HTML document: it has a doctype, <html> or <body> tag. A bare <table> is not enough — pre-2001 SGML plain-text filings mark their tables with <TABLE> too.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |