Код: Выделить всё
import polars as pl
df1 = pl.DataFrame({
'type': ['A', 'O', 'B', 'O'],
'origin': ['EU', 'US', 'US', 'EU'],
'qty1': [343,11,22,-5]
})
df2 = pl.DataFrame({
'type': ['A', 'O', 'B', 'S'],
'origin': ['EU', 'US', 'US', 'AS'],
'qty2': [-200,-12,-25,8]
})
df1.join(df2, on=['type', 'origin'], how='full')
Код: Выделить всё
┌──────┬────────┬──────┬────────────┬──────────────┬──────┐
│ type ┆ origin ┆ qty1 ┆ type_right ┆ origin_right ┆ qty2 │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ i64 ┆ str ┆ str ┆ i64 │
╞══════╪════════╪══════╪════════════╪══════════════╪══════╡
│ A ┆ EU ┆ 343 ┆ A ┆ EU ┆ -200 │
│ O ┆ US ┆ 11 ┆ O ┆ US ┆ -12 │
│ B ┆ US ┆ 22 ┆ B ┆ US ┆ -25 │
│ null ┆ null ┆ null ┆ S ┆ AS ┆ 8 │
│ O ┆ EU ┆ -5 ┆ null ┆ null ┆ null │
└──────┴────────┴──────┴────────────┴──────────────┴──────┘
Код: Выделить всё
┌──────┬────────┬──────┬──────┐
│ type ┆ origin ┆ qty1 ┆ qty2 │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ i64 ┆ i64 │
╞══════╪════════╪══════╪══════╡
│ A ┆ EU ┆ 343 ┆ -200 │
│ O ┆ US ┆ 11 ┆ -12 │
│ B ┆ US ┆ 22 ┆ -25 │
│ S ┆ AS ┆ null ┆ 8 │
│ O ┆ EU ┆ -5 ┆ null │
└──────┴────────┴──────┴──────┘
Код: Выделить всё
DuplicateError: unable to hstack, column with name "type" already exists
Подробнее здесь: https://stackoverflow.com/questions/788 ... out-suffix