You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Result: only lk column is kept. IIRC in SQL, in a SELECT with a join, both columns are kept around and you can choose which ones to keep with columns in SELECT. But doing a polars .select("rk") won't work because it's already gone.
FYI, you can return both columns by setting coalesce=False, though we could probably make the "coalesce" docstring even more explicit about what it means to coalesce the join columns (eg: keeps the left-hand column) 🤔
df1.join(df2, how="inner", left_on="lk", right_on="rk", coalesce=False)
# shape: (3, 4)# ┌─────┬─────┬─────┬─────┐# │ a ┆ lk ┆ b ┆ rk │# │ --- ┆ --- ┆ --- ┆ --- │# │ str ┆ i64 ┆ str ┆ i64 │# ╞═════╪═════╪═════╪═════╡# │ x ┆ 1 ┆ x ┆ 1 │# │ y ┆ 2 ┆ y ┆ 2 │# │ z ┆ 3 ┆ z ┆ 3 │# └─────┴─────┴─────┴─────┘
I see. There's no indication that an inner join will only keep the left key, especially since inner joins are symmetric.
Incidentally, SQL has a poorly names COALESCE function that does something completely different.
Description
Result: only
lk
column is kept. IIRC in SQL, in a SELECT with a join, both columns are kept around and you can choose which ones to keep with columns in SELECT. But doing a polars.select("rk")
won't work because it's already gone.Link
https://docs.pola.rs/api/python/stable/reference/dataframe/api/polars.DataFrame.join.html
The text was updated successfully, but these errors were encountered: