【问题标题】:Issue with Left Outer Join in Julia DataFrameJulia DataFrame 中的左外连接问题
【发布时间】:2020-05-16 11:35:31
【问题描述】:

这个让我难过。

我试图在 Julia 中加入两个数据帧,但我得到了这个奇怪的“无”错误。这适用于不同的机器,所以我认为这可能是包装问题。我 Pkg.rm() 一切并重新安装但不行。

朱莉娅 v1.2

using PyCall;
using DataFrames;
using CSV;
using Statistics;
using StatsBase;
using Random;
using Plots;
using Dates;
using Missings;
using RollingFunctions;
# using Indicators;
using Pandas;
using GLM;
using Impute;


a = DataFrames.DataFrame(x = [1, 2, 3], y = ["a", "b", "c"])

b = DataFrames.DataFrame(x = [1, 2, 3, 4], z = ["d", "e", "f", "g"])

join(a, b, on=:x, kind =:left)

产量

ArgumentError: `nothing` should not be printed; use `show`, `repr`, or custom output instead.

Stacktrace:
 [1] print(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Nothing) at ./show.jl:587
 [2] print_to_string(::String, ::Vararg{Any,N} where N) at ./strings/io.jl:129
 [3] string at ./strings/io.jl:168 [inlined]
 [4] #join#543(::Symbol, ::Symbol, ::Bool, ::Nothing, ::Tuple{Bool,Bool}, ::typeof(join), ::DataFrames.DataFrame, ::DataFrames.DataFrame) at /Users/username/.julia/packages/DataFrames/3ZmR2/src/deprecated.jl:298
 [5] (::getfield(Base, Symbol("#kw##join")))(::NamedTuple{(:on, :kind),Tuple{Symbol,Symbol}}, ::typeof(join), ::DataFrames.DataFrame, ::DataFrames.DataFrame) at ./none:0
 [6] top-level scope at In[15]:4

kind=:inner 可以正常工作,但 :left、:right 和 :outer 不行。

【问题讨论】:

    标签: dataframe join julia


    【解决方案1】:

    这是由 Julia 1.2 打印 nothing 的方式引起的问题(即尝试打印时出错)。如果您切换到 Julia 1.4.1,问题就会消失。

    但是,我可以看到您在 DataFrames.jl 0.21 上。在此版本中,join 函数已弃用。你应该使用innerjoinleftjoinrightjoinouterjoin等函数。然后一切都将在 Julia 1.2 上运行,例如:

    julia> leftjoin(a, b, on=:x)
    3×3 DataFrame
    │ Row │ x     │ y      │ z       │
    │     │ Int64 │ String │ String? │
    ├─────┼───────┼────────┼─────────┤
    │ 1   │ 1     │ a      │ d       │
    │ 2   │ 2     │ b      │ e       │
    │ 3   │ 3     │ c      │ f       │
    

    【讨论】:

    • 我很高兴听到他们终于解决了 nothing 的问题!
    猜你喜欢
    • 1970-01-01
    • 2011-07-21
    • 2013-01-31
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多