As you can see, the ind column takes every other day.
And now I want to automatically reindex the vals entries to not every other day, but every day.
So, I would like to get a dataframe that looks like this (I arbitrarily set the missing values to zero)
I think what @Henrique_Becker has proposed is actually the best solution and also quite modular. (Depending on your use case, maybe cols=:union would help as well.) I don’t know of a better way to do it.
My problem with a more generic solution is how many things are left to decide by the user, to the point that just passing all information to the generic solution is not much different from writing specific code. For example, from where the generic code will take the values for the other columns? It should make all of them Union{PreviousType, Missing} and fill with missing, or it should take a default value as argument for each column? The gaps in the index column should be automatically recognized and filled, or they will always be explicitly passed on? If this is a very common action then maybe it is worth creating a function for it, but for one or two uses I would follow that pattern and adapt it to the specifics of that occurrence.
I think the comparison with pandas leads you astray - there is nothing like the idea of an “index” in pandas in DataFrames (and I’d say that’s for the better given how often I’ve struggled with this back when I was a pandas user).
I would naturally use leftjoin here - create a DataFrame with the indexing column you want, and then leftjoin onto that. This will give missing where no match is found, and you can coalesce if you want to replace the missings with some value.
j=1
for i in 1:length(dff.ind)
global j
if df.ind[j]==dff.ind[i]
dff.vals[i]=df.vals[j]
if j<length(df.ind)
j=j+1
end
end
end
or, as very last resource ,
map(x-> x.ind in df.ind ? x.vals= df[df.ind.==x.ind,:vals][1] : x.vals, eachrow(dff))
(*)
I tried to check this code (to see how, step after step, things are going) using debug under vscode environment. But failed.
this was my first attempt at using debugging.
Where can I get help on this topic?