forestploter.read_forest_data
- forestploter.read_forest_data(source, *, sheet_name=0, header_row=1, mapping=None, encoding='utf-8-sig')[source]
Read an XLSX or CSV file that follows the forest long-table contract.
- Parameters:
- sourcestr or pathlib.Path
Path to an
.xlsxor.csvfile. Other suffixes are not guessed.- sheet_namestr or int, default 0
XLSX worksheet name or zero-based index. CSV has no worksheets and rejects any value other than the default
0.- header_rowint, default 1
One-based physical row containing field names. Every non-empty physical row below it is one source record.
- mappingForestDataMapping, optional
Reserved-field name mapping. The nine standard names are used by default.
- encodingstr, default “utf-8-sig”
CSV text encoding. Ignored for XLSX.
- Returns:
- ForestData
Long-table values, supported XLSX merges, and traceable source-cell references.
- Raises:
- FileNotFoundError
Raised when
sourcedoes not exist.- TypeError
Raised for invalid
header_row,sheet_name, ormappingtypes.- ValueError
Raised when the file type, header, worksheet, merge, or cached formula result violates the contract.
- ImportError
Raised when XLSX support is requested without
openpyxl.
- Parameters:
source (str | Path)
sheet_name (str | int)
header_row (int)
mapping (ForestDataMapping | None)
encoding (str)
- Return type:
Notes
Use a first worksheet named
Forestand one row of unique field names. Two orders are deliberately independent:The
columnsargument offorestploter.forest()is the only thing that determines the final left-to-right plot order. Display columns may appear before or after any CI column.The XLSX/CSV header order exists for readable data entry and does not determine plot order. A recommended file places display fields that precede the first CI first, then
estimate/lower/upperas the physical representation of that CI, then trailing display fields, and finally the six controls_plot_row,_series,_ci_column,_row_type,_indent, and_is_summary.
Enter only one statistical triple per estimate record. For three series, the recommended hierarchy uses one
headerrecord for the shared outcome, sample size, and other group-level values, followed by three series rows with distinct_plot_rowvalues and_indent=1. Put each series label and CI text on its child row. This conventional layout works identically in XLSX and CSV and requires no merged cells. Supported vertical XLSX merges remain available when a centered multirow display value is specifically desired. On the header record, leave_series,_ci_column, andestimate/lower/upperblank; use_row_type="header",_indent=0, and_is_summary=False.To show the same series in two CI columns, duplicate its record, use a different
_ci_column, and retain the same_plot_row. The two plotted intervals will share one y position.Merges are accepted only in display fields and must be single-column, vertical ranges below the header. Merges in reserved fields, horizontal or rectangular merges, and merges crossing the header are rejected. Blank values are never forward-filled. All three of
estimate/lower/uppermay be blank to skip an interval; a partially blank triple fails validation inforestploter.forest().The package does not evaluate Excel formulas. It uses cached results saved in the workbook and asks the user to recalculate and save when a required formula has no cache. CSV follows the same record and
_plot_rowrules, but cannot represent merges. Excel fonts, fills, borders, row heights, and column widths do not overrideforestploter.ForestThemeorforestploter.ForestColumnsettings.Examples
>>> from forestploter import read_forest_data >>> df = read_forest_data("forest_input.xlsx", sheet_name="Forest") >>> df.frame.columns[:5].tolist() ['Outcome', 'estimate', 'lower', 'upper', 'Effect [95% CI]']