I am trying to understand how DataFrames work in Julia and I am having a rough time.
I usually worked with DataFrames --in Python-- adding new columns on every simulation step and populating each row with values.
For example, I have this DataFrame which contains input Data:
using DataFrames
df = DataFrame( A=Int[], B=Int[] )
push!(df, [1, 10])
push!(df, [2, 20])
push!(df, [3, 30])
Now, let's say that I do calculations based on those A
and B
columns that generate a third column C
with DateTime objects. But DateTime objects are not generated for all rows, they could be null.
- How is that use case handled in Julia?
- How shall I create the new C column and assign values inside the
for r in eachrow(df)
?
# Pseudocode of what I intend to do
df[! :C] .= nothing
for r in eachrow(df)
if condition
r.C = mySuperComplexFunctionThatReturnsDateTimeForEachRow()
else
r.C = nothing
end
end
To give a runable and concrete code, let's fake condition and function:
df[! :C] .= nothing
for r in eachrow(df)
if r.A == 2
r.C = Dates.now()
else
r.C = nothing
end
end