# How to remove rows containing missing from DataFrame?

**URL:** <https://discourse.julialang.org/t/how-to-remove-rows-containing-missing-from-dataframe/12234>\
**Category:** New to Julia\
**Created:** [July 7, 2018, 11:21am UTC](https://discourse.julialang.org/t/how-to-remove-rows-containing-missing-from-dataframe/12234 "2018-07-07T11:21:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gyslain](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gyslain/32/4411_2.png) [@Gyslain](https://discourse.julialang.org/u/Gyslain)\
**Post date:** [July 7, 2018, 11:21am UTC](https://discourse.julialang.org/t/how-to-remove-rows-containing-missing-from-dataframe/12234/1 "2018-07-07T11:21:39Z")

</div>

Hi, given this DataFrame :

```julia
A=DataFrame(a=[1:2;missing;4], b=1:4)
4×2 DataFrames.DataFrame
│ Row │ a │ b │
├─────┼─────────┼───┤
│ 1 │ 1 │ 1 │
│ 2 │ 2 │ 2 │
│ 3 │ missing │ 3 │
│ 4 │ 4 │ 4 │

eltypes(A)
2-element Array{Type,1}:
 Union{Int64, Missings.Missing}
 Int64

```

how can I remove missings so to get :

```julia
3×2 DataFrames.DataFrame
│ Row │ a │ b │
├─────┼───┼───┤
│ 1 │ 1 │ 1 │
│ 2 │ 2 │ 2 │
│ 3 │ 4 │ 4 │

eltypes(ans)
2-element Array{Type,1}:
 Int64
 Int64

```

Thanks for help.

---

<div class="post-metadata">

**Author:** ![swt30](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swt30/32/4667_2.png) [@swt30](https://discourse.julialang.org/u/swt30)\
**Post date:** [July 7, 2018, 11:45am UTC](https://discourse.julialang.org/t/how-to-remove-rows-containing-missing-from-dataframe/12234/2 "2018-07-07T11:45:22Z")

</div>

Use `completecases` to get the rows that are not missing, then index into A:

```julia
A[completecases(A), :]

```

---

<div class="post-metadata">

**Author:** ![swt30](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swt30/32/4667_2.png) [@swt30](https://discourse.julialang.org/u/swt30)\
**Post date:** [July 7, 2018, 11:50am UTC](https://discourse.julialang.org/t/how-to-remove-rows-containing-missing-from-dataframe/12234/3 "2018-07-07T11:50:48Z")

</div>

Oh and then if you want the column types to not allow for missing values, you will need to call `disallowmissing!` on the result as well. So:

```julia
julia> A = DataFrame(a = [1:2;missing;4], b = 1:4)
4×2 DataFrames.DataFrame
│ Row │ a │ b │
├─────┼─────────┼───┤
│ 1 │ 1 │ 1 │
│ 2 │ 2 │ 2 │
│ 3 │ missing │ 3 │
│ 4 │ 4 │ 4 │

julia> eltypes(A)
2-element Array{Type,1}:
 Union{Int64, Missings.Missing}
 Int64                         

julia> B = A[completecases(A), :]
3×2 DataFrames.DataFrame
│ Row │ a │ b │
├─────┼───┼───┤
│ 1 │ 1 │ 1 │
│ 2 │ 2 │ 2 │
│ 3 │ 4 │ 4 │

julia> eltypes(B)
2-element Array{Type,1}:
 Union{Int64, Missings.Missing}
 Int64                         

julia> disallowmissing!(B)
3×2 DataFrames.DataFrame
│ Row │ a │ b │
├─────┼───┼───┤
│ 1 │ 1 │ 1 │
│ 2 │ 2 │ 2 │
│ 3 │ 4 │ 4 │

julia> eltypes(B)
2-element Array{Type,1}:
 Int64
 Int64

```

---

<div class="post-metadata">

**Author:** ![Gyslain](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gyslain/32/4411_2.png) [@Gyslain](https://discourse.julialang.org/u/Gyslain)\
**Post date:** [July 7, 2018, 1:11pm UTC](https://discourse.julialang.org/t/how-to-remove-rows-containing-missing-from-dataframe/12234/4 "2018-07-07T13:11:48Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [July 7, 2018, 6:40pm UTC](https://discourse.julialang.org/t/how-to-remove-rows-containing-missing-from-dataframe/12234/5 "2018-07-07T18:40:24Z")

</div>

`dropmissing` and `dropmissing!` are slightly more convenient ways of doing this.

---

<div class="post-metadata">

**Author:** ![Alec\_Loudenback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alec_loudenback/32/278_2.png) [@Alec\_Loudenback](https://discourse.julialang.org/u/Alec_Loudenback)\
**Post date:** [July 22, 2019, 8:56pm UTC](https://discourse.julialang.org/t/how-to-remove-rows-containing-missing-from-dataframe/12234/6 "2019-07-22T20:56:36Z")

</div>

What’s the nicest way to filter `missing`s out based on a single column? E.g. if the original example were

```julia
│ Row │ a │ b │
├─────┼─────────┼─────────┤
│ 1 │ 1 │ missing │
│ 2 │ 2 │ 2 │
│ 3 │ missing │ 3 │
│ 4 │ 4 │ 4 │

```

And I wanted to filter out the `missing`s only in column a so that I got

```julia
│ Row │ a │ b │
├─────┼───┼─────────┤
│ 1 │ 1 │ missing │
│ 2 │ 2 │ 2 │
│ 3 │ 4 │ 4 │

```

---

<div class="post-metadata">

**Author:** ![Alec\_Loudenback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alec_loudenback/32/278_2.png) [@Alec\_Loudenback](https://discourse.julialang.org/u/Alec_Loudenback)\
**Post date:** [July 22, 2019, 10:07pm UTC](https://discourse.julialang.org/t/how-to-remove-rows-containing-missing-from-dataframe/12234/7 "2019-07-22T22:07:01Z")

</div>

Found the answer in the docs. In this case, it would be:

`dropmissing(df, :a)`
