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:

  1. @orderby leftjoined :grade_2021
namegrade_2020grade_2021
Bob5.05
Alice8.55
Hank4.06.0
Sally1.09.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:

  1. @orderby leftjoined -:grade_2021
namegrade_2020grade_2021
Sally1.09.5
Hank4.06.0
Bob5.05
Alice8.55

Like all the other DataFramesMeta.jl macros, @orderby also supports multiple operations inside a begin ... end statement:

  1. @orderby leftjoined begin
  2. :grade_2021
  3. :name
  4. end
namegrade_2020grade_2021
Alice8.55
Bob5.05
Hank4.06.0
Sally1.09.5

Here, we are sorting first by grade in 2020 then by name. Both in ascending order.

5.5 Row Sorting - 图1 Support this project
CC BY-NC-SA 4.0 Jose Storopoli, Rik Huijzer, Lazaro Alonso