如何在 Julia 中连接 DataFrame 数组?

Leo*_* Jr 2 dataframe julia

我试图通过连接每个 中的公共列来将DataFrames我拥有的数组减少为一个。DataFrameDataFrame

这是我迄今为止尝试过的示例:

using DataFrames

samples=[DataFrame(x=[1,2,3],y=[1,2,3]),DataFrame(x=[4,5,6],y=[4,5,6]),DataFrame(x=[7,8,9],y=[7,8,9])]

hcat(select.(samples,:y)[1],select.(samples,:y)[2],select.(samples,:y)[3],makeunique=true) #this works

hcat(select.(samples,:y),makeunique=true)    #this doesn't

Run Code Online (Sandbox Code Playgroud)

前一种解决方案的问题是samples数组可能会根据数据任意长。

似乎只为方法makeunique定义;DataFrame我需要定义一个新DataFrames hcat方法吗?或者我可以以某种方式“输入”每个内容DataFrame,以便hcat将其解释为列表DataFrames吗?

PaS*_*STE 5

DataFrames包定义了一个hcat接受可变数量对象的函数DataFrame。您所要做的就是解压操作符返回Array{DataFrame,2}的内容,如下所示:select....

\n
julia> hcat(select.(samples, :y)..., makeunique=true)\n3\xc3\x973 DataFrame\n\xe2\x94\x82 Row \xe2\x94\x82 y     \xe2\x94\x82 y_1   \xe2\x94\x82 y_2   \xe2\x94\x82\n\xe2\x94\x82     \xe2\x94\x82 Int64 \xe2\x94\x82 Int64 \xe2\x94\x82 Int64 \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 1   \xe2\x94\x82 1     \xe2\x94\x82 4     \xe2\x94\x82 7     \xe2\x94\x82\n\xe2\x94\x82 2   \xe2\x94\x82 2     \xe2\x94\x82 5     \xe2\x94\x82 8     \xe2\x94\x82\n\xe2\x94\x82 3   \xe2\x94\x82 3     \xe2\x94\x82 6     \xe2\x94\x82 9     \xe2\x94\x82\n
Run Code Online (Sandbox Code Playgroud)\n