用csv.jl写入csv文件会抛出StackOverflowError消息



CSV.write()返回:ERROR: LoadError: StackOverflowError:进一步向下声明--- the last 2 lines are repeated 39990 more times ---。这是无稽之谈,因为要写入的数据帧被确认为129x6维,没有空字段。我担心函数计算的行数超出了数据帧的维度,不应该这样做。我该如何使此函数工作?

using CSV,DataFrames
file=DataFrame(
a=1:50,
b=1:50,
c=Vector{Any}(missing,50),
d=Vector{Any}(missing,50))
CSV.write("a.csv",file)
file=CSV.read("a.csv",DataFrame)
c,d=[],[]
for i in 1:nrow(file)
push!(c,file.a[i]*file.b[i])
push!(d,file.a[i]*file.b[i]/file.a[i])
end
file[!,:c]=c
file[!,:d]=d
# I found no straight forward way to fill empty columns based on the values of filled columns in a for loop that wouldn't generate error messages
CSV.write("a.csv",DataFrame) # Error in question here

StackOverflowError确实是由于行

CSV.write("a.csv",DataFrame)

它试图将数据类型本身写入文件,而不是实际的数据帧变量。(导致这个特殊错误的原因是这里描述的实现细节。(

# I found no straight forward way to fill empty columns based on the values of filled columns in a for loop that wouldn't generate error messages

您不需要for循环,只需要

file.c = file.a .* file.b
file.d = file.a .* file.b ./ file.a

将完成这项工作。(虽然我不明白file.d计算的意义——也许这只是你为了说明而选择的一个样本伪计算。(

最新更新