Код: Выделить всё
shape: (1, 3)
┌───────────────────────────┬───────────────────────────┬───────────────┐
│ struct1 ┆ struct2 ┆ match_results │
│ --- ┆ --- ┆ --- │
│ struct[2] ┆ struct[2] ┆ list[bool] │
╞═══════════════════════════╪═══════════════════════════╪═══════════════╡
│ {["id1", "id2"],[10, 20]} ┆ {["id4", "id1"],[10, 10]} ┆ [true, false] │
└───────────────────────────┴───────────────────────────┴───────────────┘
Код: Выделить всё
def compare_structs(struct1, struct2):
ids1, vals1 = struct1["identifiers"], struct1["values"]
ids2, vals2 = struct2["identifiers"], struct2["values"]
return [
any(id1 == id2 and val1 == val2 for id2, val2 in zip(ids2, vals2))
for id1, val1 in zip(ids1, vals1)
]
df.with_columns(
pl.struct(["struct1", "struct2"])
.map_elements(lambda s: compare_structs(s["struct1"], s["struct2"]))
.alias("match_results")
)
Подробнее здесь: https://stackoverflow.com/questions/792 ... s-row-wise