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.