Julia DataFrames 连接函数出现重复列错误

问题描述 投票:0回答:1

我想知道在

x
中是否有关键字参数或连接 DataFrames
y
leftjoin!()
的解决方法,以便
d
中的
x
列的值替换为
d 的值
y
内而不是返回错误。

using DataFrames
x=DataFrame(a=[1,2,3],b=[4,5,6],c=[7,8,9],d=[nothing,nothing,nothing])
y=DataFrame(a=[1,2,3],b=[4,5,6],c=[7,8,9],d=[20,21,22])
leftjoin!(x,y,on=[:a,:b,:c]) # returns error

所需输出:

3×4 DataFrame
 Row │ a      b      c      d
     │ Int64  Int64  Int64  Int64
─────┼────────────────────────────
   1 │     1      4      7     20
   2 │     2      5      8     21
   3 │     3      6      9     22
dataframe join error-handling julia left-join
1个回答
0
投票

首先,这个问题问得好。

其次,

select(
  leftjoin!(x,y,on=[:a,:b,:c]; makeunique=true),
  Not(r"d"),:d_1 => identity => :d)

可能是一个答案。

d
列并不完美,因为它选择了
Missing
类型。

© www.soinside.com 2019 - 2024. All rights reserved.