XLookup
Excel XLOOKUP / RECHERCHEX on Spark DataFrames.
- fabrictools.excel.lookup.XLookup(left: pyspark.sql.DataFrame, lookup_col: str, right: pyspark.sql.DataFrame, match_col: str, return_col: str, *, default: Any = None, output_name: str | None = None) pyspark.sql.DataFrame[source]
Lookup a value from
rightand add it toleft(ExcelXLOOKUP/RECHERCHEX).Performs a left join on
lookup_col(left) andmatch_col(right), keeping the first match whenrightcontains duplicate keys (Excel behaviour).- Parameters:
left (DataFrame) – Driving dataframe (equivalent to the row with
[@[lookup_col]]).lookup_col (str) – Column on
leftholding the lookup key.right (DataFrame) – Lookup table.
match_col (str) – Column on
rightto match against.return_col (str) – Column on
rightwhose value is returned.default (Any) – Value used when no match is found (
Nonekeeps null).output_name (str | None) – Name of the added column (defaults to
return_col).
- Returns:
leftwith the looked-up column appended.- Return type:
DataFrame
- Raises:
ValueError – If a required column does not resolve.
Example
>>> from fabrictools import Excel >>> df = Excel.XLookup(projects, "RAO CODE", customer_projects, "RAO CODE", "Date")