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

Allow end to select last column. #3209

Closed
nathanrboyer opened this issue Oct 26, 2022 · 1 comment
Closed

Allow end to select last column. #3209

nathanrboyer opened this issue Oct 26, 2022 · 1 comment

Comments

@nathanrboyer
Copy link
Contributor

nathanrboyer commented Oct 26, 2022

I was trying to hcat the last column of a data frame onto another data frame and was surprised that the end keyword does not work for selecting data frame columns. df[:, end] selected the correct data, but it drops the column name. It would be convenient if end worked as an alias for the last integer index like it does for array indexing. (The ncol(df) workaround is easy enough if this is difficult to implement though.)

julia> df = DataFrame(rand(3,3), :auto)
3×3 DataFrame
 Row │ x1        x2        x3       
     │ Float64   Float64   Float64
─────┼──────────────────────────────
   10.993444  0.609605  0.32879
   20.195981  0.417102  0.843341
   30.441776  0.205019  0.975706

julia> select(df, 1)
3×1 DataFrame
 Row │ x1       
     │ Float64
─────┼──────────
   10.993444
   20.195981
   30.441776

julia> select(df, end)
ERROR: syntax: unexpected "end"
Stacktrace:
 [1] top-level scope
   @ none:1

julia> select(df, Cols([end]))
ERROR: syntax: unexpected "end"
Stacktrace:
 [1] top-level scope
   @ none:1

julia> select(df, ncol(df))
3×1 DataFrame
 Row │ x3       
     │ Float64
─────┼──────────
   10.32879
   20.843341
   30.975706
@bkamins
Copy link
Member

bkamins commented Oct 26, 2022

What you propose is syntactically not possible (this is disallowed by Julia). What you can do is df[:, [end]] instead.

@bkamins bkamins closed this as completed Oct 26, 2022
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