Hi i have column containts time.
looks like this
julia> df.TOB
391-element SentinelArrays.ChainedVector{Union{Missing, Time}, SentinelArrays.SentinelVector{Time, Time, Missing, Vector{Time}}}:
12:30:00
12:30:00
12:30:00
07:47:00
Here is summary of column
TOB (min) 01:15:00 (med) 13:23:00 (max) 23:38:00 7 Union{Missing, Time}
Time is missing in 7 rows out of 391 rows.
I want fill missing rows with time “12:00:00”,
I want column to be in time format after filling.
Can someone help me to do this
Thanks
You can use Impute.jl to fill missing
values with another value in an Array:
julia> using Impute
julia> timestamps = [Time(12, 30),Time(12, 30), missing, missing, Time(15,30), Time(16, 30)]
6-element Vector{Union{Missing, Time}}:
12:30:00
12:30:00
missing
missing
15:30:00
16:30:00
julia> Impute.fill(timestamps, value=Time(12))
6-element Vector{Union{Missing, Time}}:
12:30:00
12:30:00
12:00:00
12:00:00
15:30:00
16:30:00
There is also an in-place version: Impute.fill!()
.
1 Like
or just use coalesce
. Here is an example how to do an in-place update:
julia> timestamps = [Time(12, 30),Time(12, 30), missing, missing, Time(15,30), Time(16, 30)]
6-element Vector{Union{Missing, Time}}:
12:30:00
12:30:00
missing
missing
15:30:00
16:30:00
julia> timestamps .= coalesce.(timestamps, Time(12))
6-element Vector{Union{Missing, Time}}:
12:30:00
12:30:00
12:00:00
12:00:00
15:30:00
16:30:00
5 Likes