emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* state of the art in org-mode tables e.g. join, etc
@ 2021-02-20 21:15 John Kitchin
  2021-02-21  4:40 ` Greg Minshall
  0 siblings, 1 reply; 12+ messages in thread
From: John Kitchin @ 2021-02-20 21:15 UTC (permalink / raw)
  To: org-mode-email

[-- Attachment #1: Type: text/plain, Size: 2221 bytes --]

Is there a state of the art in using org-tables as little databases with
joins and stuff?

This package https://github.com/tbanel/orgtbljoin

seems close, but not quite what I had in mind. I don't want to modify
tables in place, or create dynamic tables. I do want to combine tables in
memory though for subsequent calculations.

I was thinking more like given the tables from that page:

#+name: quantities
| type-1   | quty |
|----------+------|
| onion    |   70 |
| tomatoe  |  120 |
| eggplant |  300 |
| tofu     |  100 |

#+name: nutrition
| type-2   | Fiber | Sugar | Protein | Carb |
|----------+-------+-------+---------+------|
| eggplant |   2.5 |   3.2 |     0.8 |  8.6 |
| tomatoe  |   0.6 |   2.1 |     0.8 |  3.4 |
| onion    |   1.3 |   4.4 |     1.3 |  9.0 |
| egg      |     0 |  18.3 |    31.9 | 18.3 |
| rice     |   0.2 |     0 |     1.5 | 16.0 |
| bread    |   0.7 |   0.7 |     3.3 | 16.0 |
| orange   |   3.1 |  11.9 |     1.3 | 17.6 |
| banana   |   2.1 |   9.9 |     0.9 | 18.5 |
| tofu     |   0.7 |   0.5 |     6.6 |  1.4 |
| nut      |   2.6 |   1.3 |     4.9 |  7.2 |
| corn     |   4.7 |   1.8 |     2.8 | 21.3 |

you would be able to do something like this:

#+BEGIN_SRC emacs-lisp
(join "quantities" "type-1" "nutrition" "type-2")
#+END_SRC

#+RESULTS:
| type-1   | quty | Fiber | Sugar | Protein | Carb |
|----------+------+-------+-------+---------+------|
| onion    |   70 |   1.3 |   4.4 |     1.3 |  9.0 |
| tomatoe  |  120 |   0.6 |   2.1 |     0.8 |  3.4 |
| eggplant |  300 |   2.5 |   3.2 |     0.8 |  8.6 |
| tofu     |  100 |   0.7 |   0.5 |     6.6 |  1.4 |

or, to sum the Fiber column:

#+BEGIN_SRC emacs-lisp :var data=(join "quantities" "type-1" "nutrition"
"type-2")
(cl-loop for row in data sum (nth 2 row)))
#+END_SRC

#+RESULTS:
: 5.1000000000000005

I have spent a lot of time with Pandas in Python lately,  and trying to
think through what some analogues with org-tables would be. I would be very
happy not to reinvent the wheel here!


John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

[-- Attachment #2: Type: text/html, Size: 3117 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-02-25 14:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-20 21:15 state of the art in org-mode tables e.g. join, etc John Kitchin
2021-02-21  4:40 ` Greg Minshall
2021-02-21  6:45   ` Tim Cross
2021-02-21 15:03     ` John Kitchin
2021-02-21 16:23       ` John Kitchin
2021-02-22  6:52         ` Cook, Malcolm
2021-02-22  8:12           ` Greg Minshall
2021-02-22 15:21             ` Cook, Malcolm
2021-02-22 18:41               ` Greg Minshall
2021-02-25 14:50           ` John Kitchin
2021-02-22  8:27         ` Derek Feichtinger
2021-02-24 22:21           ` John Kitchin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).