5.5 Row Sorting
DataFramesMeta.jl
has a macro for sorting rows: @orderby
. @orderby
does not have an in-place or vectorized variant.
Let’s sort our leftjoined
by grade in 2021:
@orderby leftjoined :grade_2021
name | grade_2020 | grade_2021 |
---|---|---|
Bob | 5.0 | 5 |
Alice | 8.5 | 5 |
Hank | 4.0 | 6.0 |
Sally | 1.0 | 9.5 |
By default, @orderby
will sort in ascending order. But you can change this to decreasing order with the minus sign -
in front of the column:
@orderby leftjoined -:grade_2021
name | grade_2020 | grade_2021 |
---|---|---|
Sally | 1.0 | 9.5 |
Hank | 4.0 | 6.0 |
Bob | 5.0 | 5 |
Alice | 8.5 | 5 |
Like all the other DataFramesMeta.jl
macros, @orderby
also supports multiple operations inside a begin ... end
statement:
@orderby leftjoined begin
:grade_2021
:name
end
name | grade_2020 | grade_2021 |
---|---|---|
Alice | 8.5 | 5 |
Bob | 5.0 | 5 |
Hank | 4.0 | 6.0 |
Sally | 1.0 | 9.5 |
Here, we are sorting first by grade in 2020 then by name. Both in ascending order.
Support this project
CC BY-NC-SA 4.0 Jose Storopoli, Rik Huijzer, Lazaro Alonso
当前内容版权归 JuliaDataScience 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 JuliaDataScience .