Imagine I have a data frame like below:

What I want to do is to fill those missing values with previous values, so after fillling the data frame would be like:

Is there any simple way that I can do this?
This is the way to do it using Impute.jl:
julia> using Impute, DataFrames
julia> df = DataFrame(dt1=[0.2, missing, missing, 1, missing, 5, 6],
dt2=[0.3, missing, missing, 3, missing, 5, 6])
7×2 DataFrame
Row │ dt1 dt2
│ Float64? Float64?
─────┼──────────────────────
1 │ 0.2 0.3
2 │ missing missing
3 │ missing missing
4 │ 1.0 3.0
5 │ missing missing
6 │ 5.0 5.0
7 │ 6.0 6.0
julia> transform(df, names(df) .=> Impute.locf, renamecols=false)
7×2 DataFrame
Row │ dt1 dt2
│ Float64? Float64?
─────┼────────────────────
1 │ 0.2 0.3
2 │ 0.2 0.3
3 │ 0.2 0.3
4 │ 1.0 3.0
5 │ 1.0 3.0
6 │ 5.0 5.0
7 │ 6.0 6.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With