map_to_sdmx()
Map DataFrame columns to SDMX values using a lookup mapping.
Usage
map_to_sdmx(
df,
mapping,
)This function transforms the given DataFrame columns to conform to the SDMX representation by applying either a fixed mapping or an ordered, regex-based mapping. For each key present in the DataFrame:
- Fixed Mapping:
If the mapping for a key contains a ``TARGET`` column but no
``SOURCE`` column, the entire column is replaced with the fixed
value provided by ``TARGET``.
- Regex-based Mapping:
If the mapping for a key contains both ``SOURCE`` and ``TARGET``
columns, the function applies ordered regex-based matching using
a first-match-wins strategy.
Parameters
df: pd.DataFrame-
The input DataFrame containing the data to be mapped.
mapping: dict-
The lookup mapping as a dict. Each key represents an SDMX component and its value is expected to be either a list of dictionaries (with keys
SOURCEandTARGET) or a DataFrame with those columns.
Returns
pd.DataFrame- The transformed DataFrame with mapped column values.
Raises
ValueError- If the schema version is unsupported.