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

Dropping multiple columns #275

Closed
permanentrance opened this issue Jul 30, 2021 · 4 comments
Closed

Dropping multiple columns #275

permanentrance opened this issue Jul 30, 2021 · 4 comments

Comments

@permanentrance
Copy link

Is there a way of dropping multiple columns with @chain?

For example, I could chain multiple calls to select and that would work:

df = DataFrame(a = repeat(1:4, outer = 2), b = repeat(2:-1:1, outer = 4), c = 1:8);
@chain df begin
  select(Not(:a))
  select(Not(:b))
end

But I was wondering if there is a cleaner way of doing it, maybe with @select ?

@pdeffebach
Copy link
Collaborator

Yes, you can wrap it in cols, i.t. @select(df, cols(Not(:a))

julia> @chain df begin
         @select(cols(Not(:a)))
         @select(cols(Not(:b)))
       end
8×1 DataFrame
 Row │ c
     │ Int64
─────┼───────
   1 │     1
   2 │     2
   3 │     3
   4 │     4
   5 │     5
   6 │     6
   7 │     7
   8 │     8

This is ugly syntax, but soon cols will be replaced by $, so it will look less noisy. The PR has already been merged into master here.

@bkamins
Copy link
Member

bkamins commented Jul 31, 2021

Also note you can just write Not([:a, :b]) if this is something you are looking for.

In DataFrames.jl we try to ensure that what provide is fully composable. Here - it means that you can throw ANY column selector as an argumen to Not.

@pdeffebach
Copy link
Collaborator

ref #283

@pdeffebach
Copy link
Collaborator

Closed to focus on #283

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

3 participants