美文网首页
julia dataframe增加row的方法

julia dataframe增加row的方法

作者: 昵称违法 | 来源:发表于2020-09-20 13:04 被阅读0次

两种途径
(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)

相关文章

  • julia dataframe增加row的方法

    两种途径(1)给定的是一个数组(一行)的话,直接用push!(2)如果给定的是一个dataframe的话,直接用a...

  • bug

    DataFrame报 notFoundClass any类 =>DataFrame数据的类型为: row, 且每...

  • python dataframe导出成json格式。

    df =pd.DataFrame([['a', 'b'], ['c', 'd']], index=['row 1'...

  • tableView相关细节

    insert Row或者delete Row的时候要相应的增加和减少代理方法返回的行数。 tableView的se...

  • DataFrame与RDD区别

    DataFrame是分布式的Row对象的集合。DataFrame除了提供了比RDD更丰富的算子以外,更重要的特点是...

  • python

    一、apply&applymap&map apply 用在dataframe上,用于对row或者column进行计...

  • pandas VS baseR

    创建DataFrame 获取DataFrame维度 获取DataFrame列名 数据选取 按条件选取数据 增加新列...

  • pyspark: rdd2dataframe踩过的坑

    大纲 主要记录在rdd2dataframe遇到的问题: Input row doesn't have expect...

  • 【Python学习】No.5 常用函数

    1. apply,applymap和map的应用 总结: apply 用在dataframe上,用于对row或者c...

  • pandas 面试题挑战十二

    DataFrame中的apply方法,applymap方法有什么区别 DataFrame中的apply方法 输出 ...

网友评论

      本文标题:julia dataframe增加row的方法

      本文链接:https://www.haomeiwen.com/subject/ccnuyktx.html