# Check if value is missing in DataFrame indexed by values (not by numerical indices)

**URL:** <https://discourse.julialang.org/t/check-if-value-is-missing-in-dataframe-indexed-by-values-not-by-numerical-indices/14828>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [September 11, 2018, 7:55pm UTC](https://discourse.julialang.org/t/check-if-value-is-missing-in-dataframe-indexed-by-values-not-by-numerical-indices/14828 "2018-09-11T19:55:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmundnic](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@kmundnic](https://discourse.julialang.org/u/kmundnic)\
**Post date:** [September 11, 2018, 7:55pm UTC](https://discourse.julialang.org/t/check-if-value-is-missing-in-dataframe-indexed-by-values-not-by-numerical-indices/14828/1 "2018-09-11T19:55:34Z")

</div>

I have the following DataFrame:

```julia
julia> directories
247×133 DataFrame. Omitted printing of 127 columns
│ Row │ receiverId │ 2018-03-05 │ 2018-03-06 │ 2018-03-07 │
├─────┼──────────────────┼──────────────────────┼──────────────────────┼─────────────────────────┼
│ 1 │ 001bc50940820093 │ floor7:east:pat7302 │ floor7:east:pat7302 │ floor7:east:pat7302 │
│ 2 │ 001bc509408200fe │ floor5:south:pat5111 │ floor5:south:pat5111 │ floor5:southICU:pat5111 │
│ 3 │ 001bc5094082008e │ floor5:east:pat5307 │ floor5:east:pat5307 │ floor5:east:pat5307 │
│ 4 │ 001bc50940820018 │ floor7:south:ns04 │ floor7:south:ns04 │ floor7:south:ns04 │
│ 5 │ 001bc5094082005c │ floor5:west:ns02 │ floor5:west:ns02 │ floor5:west:ns02 │
│ 6 │ 001bc509408200ae │ floor8:west:ns01 │ floor8:west:ns01 │ floor8:west:ns01 │
│ 7 │ 001bc50940820028 │ floor7:south:pat7110 │ floor7:south:pat7110 │ floor7:south:pat7110 │
│ 8 │ 001bc50940820094 │ floor7:north:pat7217 │ floor7:north:pat7217 │ floor7:north:pat7217 │
│ 9 │ 001bc509408200b7 │ floor9:east:pat9301 │ floor9:east:pat9301 │ floor9:east:pat9301 │
│ 10 │ 001bc509408200c6 │ floor9:east:pat9304 │ floor9:east:pat9304 │ floor9:east:pat9304 │
⋮
│ 237 │ 001bc509408200f6 │ missing │ missing │ missing │
│ 238 │ 001bc50940820116 │ missing │ missing │ missing │
│ 239 │ 001bc509408200a6 │ missing │ missing │ missing │
│ 240 │ 001bc509408101f8 │ missing │ missing │ missing │
│ 241 │ 001bc50940820118 │ missing │ missing │ missing │
│ 242 │ 001bc5094082008d │ missing │ missing │ missing │
│ 243 │ 001bc5094082011a │ missing │ missing │ missing │
│ 244 │ 001bc50940820099 │ missing │ missing │ missing │
│ 245 │ 001bc50940820113 │ missing │ missing │ missing │
│ 246 │ 001bc5094082010a │ missing │ missing │ missing │
│ 247 │ 001bc509408200f2 │ missing │ missing │ missing │

```

I want to check if the receiverId `001bc509408200f6` is missing for a given date. I index the DataFrame in the following way, for a given date (column):

```julia
julia> directories[directories[:receiverId] .== "001bc509408200f6", Symbol("2018-03-05")]
1-element Array{Union{Missing, String},1}:
 missing

```

Here, the type of the output is a `1-element Array{Union{Missing, String},1}`. If I use `ismissing`, I get:

```julia
julia> ismissing(directories[directories[:receiverId] .== "001bc509408200f6", Symbol("2018-03-05")])
false

```

which is not the expected output (at least for me). If use use dot notation, since I am evaluating an array,

```julia
julia> ismissing.(directories[directories[:receiverId] .== "001bc509408200f6", Symbol("2018-03-05")])
1-element BitArray{1}:
 true

```

I get the expected output in an unexpected (again, for me) type. Therefore, I can’t for example use it as the condition for an `if` statement (at least I haven’t figured out how).

What’s the right way to check whether a value is missing when indexing a DataFrame with an array of Booleans? Note that if I index using numbers, e.g.

```julia
julia> ismissing(directories[237,2])
true

```

this just works. However, for the processing I’m working on, it’s easier to index by `receiverId` and date (column) values.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [September 11, 2018, 8:12pm UTC](https://discourse.julialang.org/t/check-if-value-is-missing-in-dataframe-indexed-by-values-not-by-numerical-indices/14828/2 "2018-09-11T20:12:41Z")

</div>

The issue is that DataFrames has no way of knowing that there is only one oversvation with `df.receiverid == "001bc509408200f6"`, so it returns an array with one element rather than a scalar. To not have this behavior would lead to type instability.

One way to get a scalar return is by using `findfirst`, which will give you the index of the first row for which `df.receiverid == "001bc509408200f6"` is `true`.
