-
Notifications
You must be signed in to change notification settings - Fork 54
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
How to order descending in @orderby
?
#81
Comments
Unfortunately that doesn't seem to be supported currently. However it shouldn't be hard to support, by adding a keyword argument and passing it to |
It works for me: julia> using DataFrames, DataFramesMeta
julia> d = DataFrame(n = 1:20, x = [3, 3, 3, 3, 1, 1, 1, 2, 1, 1,
2, 1, 1, 2, 2, 2, 3, 1, 1, 2]);
julia> @orderby(d, -:x)
20×2 DataFrames.DataFrame
│ Row │ n │ x │
├─────┼────┼───┤
│ 1 │ 1 │ 3 │
│ 2 │ 2 │ 3 │
│ 3 │ 3 │ 3 │
│ 4 │ 4 │ 3 │
│ 5 │ 17 │ 3 │
│ 6 │ 8 │ 2 │
│ 7 │ 11 │ 2 │
│ 8 │ 14 │ 2 │
│ 9 │ 15 │ 2 │
│ 10 │ 16 │ 2 │
│ 11 │ 20 │ 2 │
│ 12 │ 5 │ 1 │
│ 13 │ 6 │ 1 │
│ 14 │ 7 │ 1 │
│ 15 │ 9 │ 1 │
│ 16 │ 10 │ 1 │
│ 17 │ 12 │ 1 │
│ 18 │ 13 │ 1 │
│ 19 │ 18 │ 1 │
│ 20 │ 19 │ 1 │
julia> g = groupby(d, :x);
julia> @orderby(g, -mean(:n))
DataFrames.GroupedDataFrame 3 groups with keys: Symbol[:x]
First Group:
6×2 DataFrames.SubDataFrame{Array{Int64,1}}
│ Row │ n │ x │
├─────┼────┼───┤
│ 1 │ 8 │ 2 │
│ 2 │ 11 │ 2 │
│ 3 │ 14 │ 2 │
│ 4 │ 15 │ 2 │
│ 5 │ 16 │ 2 │
│ 6 │ 20 │ 2 │
⋮
Last Group:
5×2 DataFrames.SubDataFrame{Array{Int64,1}}
│ Row │ n │ x │
├─────┼────┼───┤
│ 1 │ 1 │ 3 │
│ 2 │ 2 │ 3 │
│ 3 │ 3 │ 3 │
│ 4 │ 4 │ 3 │
│ 5 │ 17 │ 3 │
|
I guess that only works for numeric columns... |
Correct on numeric. One way around that might be to encode with a Or, someone could PR the use of a KW arg to add this feature. |
Closed in favor of #166 |
Tried adding a minus sign before the column symbol, but got the error msg
Is there any workaround? Thanks.
The text was updated successfully, but these errors were encountered: