Mitch
June 18, 2021, 2:34pm
1
Hey, thanks for the help!
I need to match the rows from column x in dataframe two, with the correct rows in data frame 1 to form a new column. The problem is visually described and solved in Python in the link below.
Is there an equivalent in Julia?
Thank you!
nilshg
June 18, 2021, 2:40pm
2
If I understand that medium post correctly itβs just a left join, so in DataFrames:
julia> using DataFrames
julia> df_1 = DataFrame(id = [1002, 1004, 1006],
first_name = ["Cersei", "Daenerys", "Arya"])
3Γ2 DataFrame
Row β id first_name
β Int64 String
ββββββΌβββββββββββββββββββ
1 β 1002 Cersei
2 β 1004 Daenerys
3 β 1006 Arya
julia> df_2 = DataFrame(id = [1003, 1004, 1005, 1002, 1006],
last_name = ["Tyrell", "Targaryen", "Snow", "Lannister", "Stark"])
5Γ2 DataFrame
Row β id last_name
β Int64 String
ββββββΌββββββββββββββββββ
1 β 1003 Tyrell
2 β 1004 Targaryen
3 β 1005 Snow
4 β 1002 Lannister
5 β 1006 Stark
julia> leftjoin(df_1, df_2, on = :id)
3Γ3 DataFrame
Row β id first_name last_name
β Int64 String String?
ββββββΌββββββββββββββββββββββββββββββ
1 β 1004 Daenerys Targaryen
2 β 1002 Cersei Lannister
3 β 1006 Arya Stark
4 Likes