Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not with non-existing columns #3375

Closed
Lincoln-Hannah opened this issue Sep 1, 2023 · 1 comment
Closed

Not with non-existing columns #3375

Lincoln-Hannah opened this issue Sep 1, 2023 · 1 comment

Comments

@Lincoln-Hannah
Copy link

x = DataFrame(a=1:2,b=2:3)

might be nice to support

x[:,Not(:a,:c)]

instead of having to write

x[:,Not( [:a,:c] ∩ propertynames(x) )]
@bkamins
Copy link
Member

bkamins commented Sep 1, 2023

Unfortunately, this is not how Not was designed to work in general (outside of DataFrames.jl):

julia> x = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> x[Not(4)]
ERROR: BoundsError: attempt to access 3-element Vector{Int64} at index [Not(4)]

so we have to stick to the same rules.

However, a way to do what you want uses Cols and :

julia> x[:, Cols(∉(["a", "c"]))]
2×1 DataFrame
 Row │ b
     │ Int64
─────┼───────
   1 │     2
   2 │     3

or equivalent:

julia> x[:, Cols(!in(["a", "c"]))]
2×1 DataFrame
 Row │ b
     │ Int64
─────┼───────
   1 │     2
   2 │     3

@bkamins bkamins closed this as completed Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants