# How to delete rows in DataFrame?

**URL:** <https://discourse.julialang.org/t/how-to-delete-rows-in-dataframe/86993>\
**Category:** New to Julia\
**Tags:** question, dataframes\
**Created:** [September 9, 2022, 2:55pm UTC](https://discourse.julialang.org/t/how-to-delete-rows-in-dataframe/86993 "2022-09-09T14:55:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhangchunyong](https://avatars.discourse-cdn.com/v4/letter/z/d9b06d/32.png) [@zhangchunyong](https://discourse.julialang.org/u/zhangchunyong)\
**Post date:** [September 9, 2022, 2:55pm UTC](https://discourse.julialang.org/t/how-to-delete-rows-in-dataframe/86993/1 "2022-09-09T14:55:36Z")

</div>

```julia
group=[:A,:A,:B,:B,:C,:C,:C,:C]
X = 100:108
df = DataFrame(; group, X)
julia> df = DataFrame(; group, X)
8×2 DataFrame
 Row │ group X
     │ Symbol Int64
─────┼───────────────
   1 │ A 101
   2 │ A 102
   3 │ B 103
   4 │ B 104
   5 │ C 105
   6 │ C 106
   7 │ C 107
   8 │ C 108

```

I want to delete the second line that starts with C, so what should I do? I do not want to write thr code like deleteat! (df,6). What I want is that the code should contain C and 2.Thanks for helping me!

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [September 9, 2022, 3:01pm UTC](https://discourse.julialang.org/t/how-to-delete-rows-in-dataframe/86993/2 "2022-09-09T15:01:39Z")

</div>

```julia
julia> deleteat!(df, findall(==(:C), df.group)[2])
7×2 DataFrame
 Row │ group X     
     │ Symbol Int64 
─────┼───────────────
   1 │ A 101
   2 │ A 102
   3 │ B 103
   4 │ B 104
   5 │ C 105
   6 │ C 107
   7 │ C 108

```

Assumes that there _is_ a second line that starts with C i.e. assumes there are at least two `C`s in the `group` column.

---

<div class="post-metadata">

**Author:** ![zhangchunyong](https://avatars.discourse-cdn.com/v4/letter/z/d9b06d/32.png) [@zhangchunyong](https://discourse.julialang.org/u/zhangchunyong)\
**Post date:** [September 12, 2022, 8:01am UTC](https://discourse.julialang.org/t/how-to-delete-rows-in-dataframe/86993/4 "2022-09-12T08:01:14Z")

</div>

Thanks.If I want the code to contain C and 106(delete the sixth row in df),what should I do?I found that the function findall didn’t work.Thanks for helping me!

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 12, 2022, 8:35am UTC](https://discourse.julialang.org/t/how-to-delete-rows-in-dataframe/86993/5 "2022-09-12T08:35:16Z")

</div>

Could you show what isn’t working? The code that @digital_carver posted above does exactly what you are asking for (delete the row in which `X` is 106).

If you are now saying you want multiple conditions you can find the index by chaining conditions with `.&&` like this:

```julia
julia> findall(df.group .== :C .&& df.X .== 106)
1-element Vector{Int64}:
 6

```

---

<div class="post-metadata">

**Author:** ![zhangchunyong](https://avatars.discourse-cdn.com/v4/letter/z/d9b06d/32.png) [@zhangchunyong](https://discourse.julialang.org/u/zhangchunyong)\
**Post date:** [September 12, 2022, 8:44am UTC](https://discourse.julialang.org/t/how-to-delete-rows-in-dataframe/86993/7 "2022-09-12T08:44:25Z")

</div>

> [@nilshg](#):
>
> `findall(df.group .== :C .&& df.X .== 106)`

Thank you
