Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

LOD_XYV

lod_xyv_transformation

Help on function lod_xyv_transformation in module pydicts.lod_xyv:

lod_xyv_transformation(ld, key_x, key_y, key_value, order=None)
    Transforms a list of dictionaries (LoD) from a "long" format (x, y, value)
    into a "wide" format (x as rows, y as columns, and value at the intersection).

    Args:
        ld (list): The input list of dictionaries. Each dictionary should have
                   keys for x-axis, y-axis, and a value.
        key_x (str): The key in the input dictionaries that represents the x-axis (rows).
        key_y (str): The key in the input dictionaries that represents the y-axis (columns).
        key_value (str): The key in the input dictionaries that holds the value.
        order (list, optional): A list specifying the desired order of columns (y-axis keys).
                                If None, columns will appear in the order they are encountered.

    Returns:
        list: A new list of dictionaries, where each dictionary represents a row (x-axis item),
              and contains keys for each y-axis item with their corresponding values.
              Returns an empty list if input `ld` is empty, or None if specified keys are not found.