Best julian way to populate empty dataframes?


Often times in what I code, I need to populate an empty dataframe based on some pre-existing dataframe which is called inside a function. For example,

function populate_meta_data(data::R) where {R<:DataFrame}
    data_1 = manipulate(data) #do something with data to return some new dataframe
    meta_data = DataFrame()   #start populating empty dataframe meta_data column-wise 
    meta_data[!, :a_new] = data_1[!, :a]
    meta_data[!, :b_new] = data_1[!, :b]
 return meta_data

What is the most performant way to do such operations?

1 Like

That seems fine. Though be careful with the ! syntax. You probably want to use a colon : so that operations that manipulate vectors in meta_data don’t affect the vectors in data_1.


Yes, I am careful regarding that aspect and thanks for flagging it! Probably safer to use colon on the RHS of the assignment.