# Slow deletion loop on huge DataFrame

**URL:** <https://discourse.julialang.org/t/slow-deletion-loop-on-huge-dataframe/90970>\
**Category:** Performance\
**Created:** [November 28, 2022, 10:44pm UTC](https://discourse.julialang.org/t/slow-deletion-loop-on-huge-dataframe/90970 "2022-11-28T22:44:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kryppi](https://avatars.discourse-cdn.com/v4/letter/k/22d042/32.png) [@Kryppi](https://discourse.julialang.org/u/Kryppi)\
**Post date:** [November 28, 2022, 10:44pm UTC](https://discourse.julialang.org/t/slow-deletion-loop-on-huge-dataframe/90970/1 "2022-11-28T22:44:24Z")

</div>

I want to delete certain elements in an ordered DataFrame dim=(1.5 million,14). If the conditions for deletion are met, the code to check if the next element is also up for deletion (if the string in [x,1] is identical) looks like this:

> **Code**
>
> while df[k-l,1]==df[k-l+1,1]  
> deleteat!(df,k-l+1)  
> l=l+1;  
> k=k+1;  
> if k==upperBoundary-1  
> break  
> end  
> end  
> deleteat!(df,k-l)  
> k+=1;  
> l+=1;  
> end

I checked with println that this part takes about 1 s (was faster for me than looking up the @time syntax again, my bad).  
This isn’t scalable.  
Suggestions?

Edit: My indents are gone. Sorry ☹

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 28, 2022, 11:03pm UTC](https://discourse.julialang.org/t/slow-deletion-loop-on-huge-dataframe/90970/2 "2022-11-28T23:03:19Z")

</div>

Try calculating all the indices you want to delete and do the deletion in one call.

---

<div class="post-metadata">

**Author:** ![Kryppi](https://avatars.discourse-cdn.com/v4/letter/k/22d042/32.png) [@Kryppi](https://discourse.julialang.org/u/Kryppi)\
**Post date:** [November 29, 2022, 9:49pm UTC](https://discourse.julialang.org/t/slow-deletion-loop-on-huge-dataframe/90970/3 "2022-11-29T21:49:59Z")

</div>

job was done within seconds.
