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

How to sort rows after aggregation? #10

Closed
wuqui opened this issue Jul 21, 2021 · 5 comments
Closed

How to sort rows after aggregation? #10

wuqui opened this issue Jul 21, 2021 · 5 comments

Comments

@wuqui
Copy link

wuqui commented Jul 21, 2021

Is it possible to sort the rows based on values after aggregation? If I group by one variable and sum values based on that grouping, it is often desired to get back the results in descending order of the calculated sum values. This would be very handy.

By the way: what a cool package, thanks a lot! I used to do all these things via Python source code blocks using pandas, but this is much quicker for simple aggregations 🤓

@tbanel
Copy link
Owner

tbanel commented Aug 4, 2021

Very good suggestion! I have sorting output in my todo list.

I am not quite sure what would be the most convenient syntax for specifying that.

  • ascending-descending, alphabetic, numeric, time&dates, custom (with custom lisp functions)
  • several columns can be specified
  • should there be a :sort option?
    :sort thiscolumn;A thatcoloumn:t
    (sort first on thiscolumn, alphabetically, descending, then on thatcolumn, as date-time, ascending)
  • or should we add something in the :cols specifier?
    :cols ... thiscolumn;A1 ... thatcolumn;t2 ...
    (sort thiscolumn 1st, alphabetically, descending, then thatcolumn 2nd, as date-time, ascending)

In the meantime, it is still possible to sort the output manually with C-c ^

@wuqui
Copy link
Author

wuqui commented Aug 4, 2021

Cool!

I think I would prefer a separate :sort argument. This way, everything will still work as usual if one doesn't need sorting.

Specifying column types for sorting the same way it's done in org-tables makes sense, I think. So :sort date_col:t alph_col:A etc. for different data types and capital letters to specify ascending/descending order.

I actually have one more idea/suggestion for your package. I'm gonna quickly open a separate issue for that since it's not related.

@tbanel
Copy link
Owner

tbanel commented Aug 11, 2021

Ok, sorting the output table is now implemented.

Sorting instructions can be added to any column, either a key column or a formula column. This is done by adding a semicolon and a caret to the column specification: mycolumn;^n. Without sorting specifications, everything works as before.

There is no separate :sort parameter, because changing, adding, or reordering columns would make things confused.

Org Mode conventions are used:

  • a/n/t for sorting alphabetically/numerically/by date
  • A/N/T for sorting in descending order

I close this issue. Feel free to open a new issue in case of a bug or something.

@tbanel tbanel closed this as completed Aug 11, 2021
@wuqui
Copy link
Author

wuqui commented Oct 31, 2021

Hey, just want to leave a big thank you! 🙂

Unfortunately, I had Emacs config issues and couldn't check it out earlier. But thanks to org-mode I didn't forget about this and I'm really glad to have this feature. Cheers!

@tbanel
Copy link
Owner

tbanel commented Nov 1, 2021

You are welcome!

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