Julia | DataFrame | Replacing missing Values

前端 未结 4 1535
爱一瞬间的悲伤
爱一瞬间的悲伤 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:14

    This is a shorter and more updated answer since Julia introduced the missing attribute recently.

    using DataFrames
    df = DataFrame(A=rand(1:50, 5), B=rand(1:50, 5), C=vcat(rand(1:50,3), missing, rand(1:50))) ## Creating random 5 integers within the range of 1:50, while introducing a missing variable in one of the rows
    df = DataFrame(replace!(convert(Matrix, df), missing=>0)) ## Converting to matrix first, since replacing values directly within type dataframe is not allowed
    

提交回复
热议问题