# Boolean false filter in update selection query

**URL:** <https://discourse.julialang.org/t/boolean-false-filter-in-update-selection-query/46203>\
**Category:** General Usage\
**Tags:** question, dataframes\
**Created:** [September 7, 2020, 2:31pm UTC](https://discourse.julialang.org/t/boolean-false-filter-in-update-selection-query/46203 "2020-09-07T14:31:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [September 7, 2020, 2:31pm UTC](https://discourse.julialang.org/t/boolean-false-filter-in-update-selection-query/46203/1 "2020-09-07T14:31:26Z")

</div>

Hello,

Am trying to update values in a dataframe as follows:

```julia
df[
    (
        df[!, :country] .== country 
        && !df[!, :bool]
    ),
    :value
] = value

```

However I receive error that non-boolean value is used in a boolean context.

Above works if I use `df[!, :bool]` (condition as true).

How can I perform above query using false condition in statement?

Thanks

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 7, 2020, 2:52pm UTC](https://discourse.julialang.org/t/boolean-false-filter-in-update-selection-query/46203/2 "2020-09-07T14:52:50Z")

</div>

Can you share a sample of `df`? That would make it easier to diagnose. I.e. a “minimum working example”

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [September 7, 2020, 3:19pm UTC](https://discourse.julialang.org/t/boolean-false-filter-in-update-selection-query/46203/3 "2020-09-07T15:19:07Z")

</div>

Is this what you are looking for:

```julia
julia> using DataFrames

julia> df = DataFrame(country = ["A", "B", "A", "A"], bool = [true, true, false, true], value = zeros(4))
4×3 DataFrame
│ Row │ country │ bool │ value │
│ │ String │ Bool │ Float64 │
├─────┼─────────┼──────┼─────────┤
│ 1 │ A │ 1 │ 0.0 │
│ 2 │ B │ 1 │ 0.0 │
│ 3 │ A │ 0 │ 0.0 │
│ 4 │ A │ 1 │ 0.0 │

julia> df[(df.country .== "A") .& df.bool, :value] = 1
1

julia> df
4×3 DataFrame
│ Row │ country │ bool │ value │
│ │ String │ Bool │ Float64 │
├─────┼─────────┼──────┼─────────┤
│ 1 │ A │ 1 │ 1.0 │
│ 2 │ B │ 1 │ 0.0 │
│ 3 │ A │ 0 │ 0.0 │
│ 4 │ A │ 1 │ 1.0 │

```

---

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [September 7, 2020, 3:23pm UTC](https://discourse.julialang.org/t/boolean-false-filter-in-update-selection-query/46203/4 "2020-09-07T15:23:15Z")

</div>

Yes this is what I am looking for. Thank you!

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [September 7, 2020, 3:24pm UTC](https://discourse.julialang.org/t/boolean-false-filter-in-update-selection-query/46203/5 "2020-09-07T15:24:57Z")

</div>

For the negation you can use

```julia
df[(df.country .== "A") .& (df.bool .!= true), :value] = 1

```

---

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [September 7, 2020, 3:26pm UTC](https://discourse.julialang.org/t/boolean-false-filter-in-update-selection-query/46203/6 "2020-09-07T15:26:46Z")

</div>

Yes makes sense. Thanks again
