build_representation_map()
Build a RepresentationMap object from a pandas DataFrame using build_value_map_list.
Usage
build_representation_map(
df,
agency="FAKE_AGENCY",
id=None,
name=None,
source_cl=None,
target_cl=None,
version="1.0",
description=None,
source_col="source",
target_col="target",
valid_from_col="valid_from",
valid_to_col="valid_to",
generate_urn=True
)Parameters
df: pd.DataFrame-
DataFrame where each row represents a mapping.
agency: str = "FAKE_AGENCY"-
Agency maintaining the representation map.
id: str | None = None-
Identifier for the representation map.
name: str | None = None-
Name of the representation map.
source_cl: str | None = None-
URN or identifier for the source codelist or data type.
target_cl: str | None = None-
URN or identifier for the target codelist or data type.
version: str = "1.0"-
Version of the representation map. Defaults to “1.0”.
description: str | None = None-
Optional description of the representation map.
source_col: str = "source"-
Column name for source values. Defaults to “source”.
target_col: str = "target"-
Column name for target values. Defaults to “target”.
valid_from_col: str = "valid_from"-
Column name for validity start date. Defaults to “valid_from”.
valid_to_col: str = "valid_to"-
Column name for validity end date. Defaults to “valid_to”.
generate_urn: bool = True- If True, automatically generate URN. Defaults to True.
Returns
RepresentationMap- A RepresentationMap object containing the mappings.
Raises
ValueError-
If DataFrame is empty or required columns are missing.
TypeError- If source or target columns contain non-string values.
Examples
>>> import pandas as pd
>>> data = {
... 'source': ['BE', 'FR'],
... 'target': ['BEL', 'FRA'],
... 'valid_from': ['2020-01-01', None],
... 'valid_to': ['2025-12-31', None]
... }
>>> df = pd.DataFrame(data)
>>> rm = build_representation_map(df, 'urn:source:codelist', 'urn:target:codelist', 'RM1', 'Country Map', 'ECB')
>>> isinstance(rm, RepresentationMap)
True