Код: Выделить всё
import polars as pl
df1 = pl.DataFrame({"col1": [1, 2, 3], "col2": ["x1, x2, x3", "x2, x3", "x3"]})
df2 = pl.DataFrame({"col3": [4, 5, 6], "col4": ["x1", "x2", "x3"]})
Код: Выделить всё
model_data = df1.join(df2, on="col2")
Код: Выделить всё
shape: (6, 4)
┌──────┬────────────┬──────┬──────┐
│ col1 ┆ col2 ┆ col3 ┆ col4 │
│ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ str ┆ i64 ┆ str │
╞══════╪════════════╪══════╪══════╡
│ 1 ┆ x1, x2, x3 ┆ 4 ┆ x1 │
│ 1 ┆ x1, x2, x3 ┆ 5 ┆ x2 │
│ 1 ┆ x1, x2, x3 ┆ 6 ┆ x3 │
│ 2 ┆ x2, x3 ┆ 5 ┆ x2 │
│ 2 ┆ x2, x3 ┆ 6 ┆ x3 │
│ 3 ┆ x3 ┆ 6 ┆ x3 │
└──────┴────────────┴──────┴──────┘
Подробнее здесь: https://stackoverflow.com/questions/743 ... her-column