# Use of Not() in select() with a function

**URL:** <https://discourse.julialang.org/t/use-of-not-in-select-with-a-function/53793>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [January 22, 2021, 5:44pm UTC](https://discourse.julialang.org/t/use-of-not-in-select-with-a-function/53793 "2021-01-22T17:44:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andferrari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andferrari/32/7715_2.png) [@andferrari](https://discourse.julialang.org/u/andferrari)\
**Post date:** [January 22, 2021, 5:44pm UTC](https://discourse.julialang.org/t/use-of-not-in-select-with-a-function/53793/1 "2021-01-22T17:44:14Z")

</div>

I try to use `Not()` column selector when applying a function in `select()` without success

```julia
julia> df = DataFrame(id1 = 1:2, id2 = 1:2)
2×2 DataFrame
 Row │ id1 id2   
     │ Int64 Int64 
─────┼──────────────
   1 │ 1 1
   2 │ 2 2

julia> select(df, Not(:id1))
2×1 DataFrame
 Row │ id2   
     │ Int64 
─────┼───────
   1 │ 1
   2 │ 2

julia> select(df, Not(:id1) .= x -> x.^2)
ERROR: MethodError: no method matching ndims(::Type{InvertedIndex{Symbol}})

```

Thank you for your help!

---

<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:** [January 22, 2021, 5:46pm UTC](https://discourse.julialang.org/t/use-of-not-in-select-with-a-function/53793/2 "2021-01-22T17:46:29Z")

</div>

`Not` is currently not broadcastable. For the time being you need `names(df, Not(:id1))`

---

<div class="post-metadata">

**Author:** ![andferrari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andferrari/32/7715_2.png) [@andferrari](https://discourse.julialang.org/u/andferrari)\
**Post date:** [January 22, 2021, 5:53pm UTC](https://discourse.julialang.org/t/use-of-not-in-select-with-a-function/53793/3 "2021-01-22T17:53:58Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![hungpham3112](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hungpham3112/32/34315_2.png) [@hungpham3112](https://discourse.julialang.org/u/hungpham3112)\
**Post date:** [May 14, 2023, 2:59pm UTC](https://discourse.julialang.org/t/use-of-not-in-select-with-a-function/53793/4 "2023-05-14T14:59:44Z")

</div>

What about @select with Not()? Does `@select` support `Not` with multiple column?

`@select df Not([:"long-name1", :"long-name2"])`

returns:

`ArgumentError: Malformed expression in DataFramesMeta.jl macro`

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [May 14, 2023, 3:10pm UTC](https://discourse.julialang.org/t/use-of-not-in-select-with-a-function/53793/5 "2023-05-14T15:10:33Z")

</div>

maybe this is the expression you need!?

```julia
select(df, Not(:id1) .=> x -> x.^2)

```

```julia
df = DataFrame(id1 = 1:2, id2 = 2:3, id3=3:4)

2×3 DataFrame
 Row │ id1 id2 id3   
     │ Int64 Int64 Int64
─────┼─────────────────────
   1 │ 1 2 3
   2 │ 2 3 4

select(df, Not(:id1))
2×2 DataFrame
 Row │ id2 id3   
     │ Int64 Int64
─────┼──────────────
   1 │ 2 3
   2 │ 3 4

select(df, Not(:id1) .=> x -> x.^2)
2×2 DataFrame
 Row │ id2_function id3_function 
     │ Int64 Int64
─────┼────────────────────────────
   1 │ 4 9
   2 │ 9 16

select(df, Not(:id1) .=>( x -> x.^2 ) => x-> x.*"^2")

```

---

<div class="post-metadata">

**Author:** ![hungpham3112](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hungpham3112/32/34315_2.png) [@hungpham3112](https://discourse.julialang.org/u/hungpham3112)\
**Post date:** [May 14, 2023, 4:59pm UTC](https://discourse.julialang.org/t/use-of-not-in-select-with-a-function/53793/6 "2023-05-14T16:59:33Z")

</div>

After researching, I found the solution for my question.

`@select df $(Not([:"long-name1", :"long-name2"]))`

Wrapping `Not` with `$()` can solve the problem. More details in here:

[https://juliadata.github.io/DataFramesMeta.jl/stable/#dollar](https://juliadata.github.io/DataFramesMeta.jl/stable/#dollar)
