I am using polar library in python and have two data frames the look like this
import polars as pl
data1 = {
'A': [1, 2, 3],
'B': [4, 5, 6],
'C': [7, 8, 9]
}
df1 = pl.DataFrame(data1)
data2 = {
'B': [4, 5, 6],
'C': [7, 8, 9],
'D': [1, 2, 3]
}
df2 = pl.DataFrame(data2)
# the column B and C are same in both data frames
# TODO: Join/Concat the data frames into one.
The data2 can vary some time it can have 2 common columns, some time it can have 1 common column and some times more. and The result should look like. I was wondering if there is any built function, or some kind of flag in a function that exists already in polars, that i can use.
result = {
'A': [1, 2, 3],
'B': [4, 5, 6],
'C': [7, 8, 9],
'D': [1, 2, 3]
}
I am not quite sure how to join
or concat
the polar data frames in order to achieve this.
You can concat with
how="align"
but the resulting column order differs.You can see how it is implemented here.
It basically finds the common columns to use as
on
and "outer joins" all the frames together.