daft.Expression.map.get

daft.Expression.map.get#

Expression.map.get(key: Expression) Expression[source]#

Retrieves the value for a key in a map column

Example

>>> import pyarrow as pa
>>> import daft
>>> pa_array = pa.array([[("a", 1)],[],[("b", 2)]], type=pa.map_(pa.string(), pa.int64()))
>>> df = daft.from_arrow(pa.table({"map_col": pa_array}))
>>> df = df.with_column("a", df["map_col"].map.get("a"))
>>> df.show()
╭──────────────────┬───────╮
│ map_col          ┆ a     │
│ ---              ┆ ---   │
│ Map[Utf8: Int64] ┆ Int64 │
╞══════════════════╪═══════╡
│ [{key: a,        ┆ 1     │
│ value: 1,        ┆       │
│ }]               ┆       │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ []               ┆ None  │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
│ [{key: b,        ┆ None  │
│ value: 2,        ┆       │
│ }]               ┆       │
╰──────────────────┴───────╯

(Showing first 3 of 3 rows)
Parameters:

key – the key to retrieve

Returns:

the value expression

Return type:

Expression