# How to reindex in DataFrames?

**URL:** <https://discourse.julialang.org/t/how-to-reindex-in-dataframes/51112>\
**Category:** Data\
**Created:** [December 2, 2020, 1:21pm UTC](https://discourse.julialang.org/t/how-to-reindex-in-dataframes/51112 "2020-12-02T13:21:57Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [December 30, 2020, 7:29am UTC](https://discourse.julialang.org/t/how-to-reindex-in-dataframes/51112/10 "2020-12-30T07:29:36Z")

</div>

using the variables already defined

```julia
dff = DataFrame(ind = full_inds, vals=0.);
sort(combine(groupby(vcat(df,dff),:ind), :vals=>sum=>:vals))

```

or

```julia
dff1 = DataFrame(ind = full_inds, vals=missing);
sort(combine(groupby(vcat(df,dff1),:ind), :vals=>(x->(coalesce(x...)))=>:vals))

```

or (\*)

```julia
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 😉,

```julia
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?

---

_[View the full topic](https://discourse.julialang.org/t/how-to-reindex-in-dataframes/51112)._
