两种途径
(1)给定的是一个数组(一行)的话,直接用push!
(2)如果给定的是一个dataframe的话,直接用append!
在给定的一行(格式为数组)时,没有必要把它变成dataframe再使用append
一、给定ary, 直接push到df中
function test4()
df = DataFrame(A = Int64[], B = Int64[],C = String[])
for i in 1:1000000
push!(df, [3,6,"朱"])
end
end
@time test4()
#1.022286 seconds (9.00 M allocations: 259.091 MiB, 1.77% gc time)
二、给定ary, 首先生成df再append到df中
function test5()
df = DataFrame(A = Int64[], B = Int64[],C = String[])
for i in 1:1000000
sss = [3,6,"朱"]
col = [:A,:B,:C]
ary = sss.|>(item) -> [item]
df1 = DataFrame(ary,col)
append!(df,df1)
end
end
@time test5()
# 13.809428 seconds (81.06 M allocations: 5.247 GiB, 4.48% gc time)
三、给定的df1, 直接append到df中
function test6()
df = DataFrame(A = Int64[], B = Int64[],C = String[])
sss = [3,6,"朱"]
col = [:A,:B,:C]
ary = sss.|>(item) -> [item]
df1 = DataFrame(ary,col)
for i in 1:1000000
append!(df,df1)
end
end
@time test6()
#0.958618 seconds (15.06 M allocations: 774.894 MiB, 6.50% gc time)
网友评论