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

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

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!

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

2 Likes

Thank you!

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

maybe this is the expression you need!?

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

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")

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