read_marc21#
- read_marc21(
- sources: str | Path | list[str] | list[Path],
- query: str,
- *,
- header: str | list[str] | None = None,
- where: str | None = None,
- skip_invalid: bool = True,
- glob: bool = False,
Read and project MARC21 files into a DataFrame.
- Parameters:
- sources
Path(s) to MARC21 files. Files with
.gzsuffix (compressed in Gzip format) are automatically decompressed.- query
A query that defines the projection to be performed.
- header
Specify the column names either as a list or as a string (comma- separated list). Any column names specified using an
ASclause are overridden by this parameter. The number of columns must always match the width of the query, and the column names must always be unique; there must be no duplicates.- where
A filter expression (record matcher) used to filter records in advance. This prevents unnecessary memory allocations and thereby improves significantly the performance of the query execution.
- skip_invalid
Whether to skip invalid records or not (default
True).- glob
When set, all sources of type
strare interpreted as glob patterns.
- Raises:
- ValueError
The number of columns does not match the width of the query (
headerparameter)The column names are not unique (
headerparameter,ASclause)
- UnicodeDecodeError
If the record does not contain valid UTF-8 values.
See also
scan_marc21Read and project MARC21 files into a LazyFrame.
Examples
>>> from marc21_learn.io import read_marc21 >>> df = read_marc21("../tests/data/ada.mrc.gz", "001 AS `cn`") >>> df shape: (1, 1) ┌───────────┐ │ cn │ │ --- │ │ str │ ╞═══════════╡ │ 119232022 │ └───────────┘