Julia | DataFrame | Replacing missing Values

前端 未结 4 1537
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-20 13:53

How can we replace missing values with 0.0 for a column in a DataFrame?

4条回答
  •  梦如初夏
    2021-02-20 14:16

    The other answers are pretty good all over. If you are a real speed junky, perhaps the following might be for you:

    # prepare example
    using DataFrames
    df = DataFrame(A = 1.0:10.0, B = 2.0:2.0:20.0)
    df[ df[:A] %2 .== 0, :B ] = NA
    
    
    df[:B].data[df[:B].na] = 0.0 # put the 0.0 into NAs
    df[:B] = df[:B].data         # with no NAs might as well use array
    

提交回复
热议问题