Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Joining polars dataframes while ignoring duplicate values in the on column

$
0
0

Given the code

df1 = pl.DataFrame({"A": [1, 1], "B": [3, 4]})df2 = pl.DataFrame({"A": [1, 1], "C": [5, 6]})result = df1.join(df2, on='A')

result looks like

shape: (4, 3)┌─────┬─────┬─────┐│ A   ┆ B   ┆ C   ││ --- ┆ --- ┆ --- ││ i64 ┆ i64 ┆ i64 │╞═════╪═════╪═════╡│ 1   ┆ 3   ┆ 5   ││ 1   ┆ 4   ┆ 5   ││ 1   ┆ 3   ┆ 6   ││ 1   ┆ 4   ┆ 6   │└─────┴─────┴─────┘

but I would like it to be

shape: (2, 3)┌─────┬─────┬─────┐│ A   ┆ B   ┆ C   ││ --- ┆ --- ┆ --- ││ i64 ┆ i64 ┆ i64 │╞═════╪═════╪═════╡│ 1   ┆ 3   ┆ 5   ││ 1   ┆ 4   ┆ 6   │└─────┴─────┴─────┘

Experimenting with left_on, right_on and how parameters did not resolve this issue.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>