emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Import CSV file, remove columns, print table
@ 2019-09-13 13:33 Loris Bennett
  2019-09-13 13:42 ` John Kitchin
  2019-09-13 14:23 ` Fraga, Eric
  0 siblings, 2 replies; 6+ messages in thread
From: Loris Bennett @ 2019-09-13 13:33 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

I want to create a list of participants of an event which people can
sign, so that I can record who actually turned up.

From the registration website I can download a CSV file and import it
into and org file:

| ID | Name         | Titel / Title | Vorname / First Name | Nachname / Surname | Institution           |
|  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple              | Universität zum Apfel |
|  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne              | Pear University       |
|  3 | Carol Carrot | Prof.         | Carol                | Carrot             | University of Veg     |


I would like to reduce this to

| ID | Nachname / Surname | Vorname / First Name | Signature |
|  1 | Apple              | Alice                |           |
|  2 | Birne              | Bob                  |           |
|  3 | Carrot             | Carol                |           |

and then print it out as a LaTeX table.

I can obviously write a source block of Python or R to do this, but can
I manipulate the table more directly in Org?

Cheers,

Loris

-- 
This signature is currently under construction.

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

* Re: Import CSV file, remove columns, print table
  2019-09-13 13:33 Import CSV file, remove columns, print table Loris Bennett
@ 2019-09-13 13:42 ` John Kitchin
  2019-09-16 12:45   ` Loris Bennett
  2019-09-13 14:23 ` Fraga, Eric
  1 sibling, 1 reply; 6+ messages in thread
From: John Kitchin @ 2019-09-13 13:42 UTC (permalink / raw)
  To: Loris Bennett; +Cc: org-mode-email

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

You can do something like this:

#+name: csv
| ID | Name         | Titel / Title | Vorname / First Name | Nachname /
Surname | Institution           |
|  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple
     | Universität zum Apfel |
|  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne
     | Pear University       |
|  3 | Carol Carrot | Prof.         | Carol                | Carrot
    | University of Veg     |


#+BEGIN_SRC emacs-lisp :var data=csv
(let ((table (mapcar (lambda (row) (list (nth 0 row) (nth 4 row) (nth 3
row))) data)))
  (setf (car table) (append (car table) '("Signature")))
  table)
#+END_SRC

#+RESULTS:
| ID | Nachname / Surname | Vorname / First Name | Signature |
|  1 | Apple              | Alice                |           |
|  2 | Birne              | Bob                  |           |
|  3 | Carrot             | Carol                |           |


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



On Fri, Sep 13, 2019 at 9:36 AM Loris Bennett <loris.bennett@fu-berlin.de>
wrote:

> Hi,
>
> I want to create a list of participants of an event which people can
> sign, so that I can record who actually turned up.
>
> From the registration website I can download a CSV file and import it
> into and org file:
>
> | ID | Name         | Titel / Title | Vorname / First Name | Nachname /
> Surname | Institution           |
> |  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple
>       | Universität zum Apfel |
> |  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne
>       | Pear University       |
> |  3 | Carol Carrot | Prof.         | Carol                | Carrot
>      | University of Veg     |
>
>
> I would like to reduce this to
>
> | ID | Nachname / Surname | Vorname / First Name | Signature |
> |  1 | Apple              | Alice                |           |
> |  2 | Birne              | Bob                  |           |
> |  3 | Carrot             | Carol                |           |
>
> and then print it out as a LaTeX table.
>
> I can obviously write a source block of Python or R to do this, but can
> I manipulate the table more directly in Org?
>
> Cheers,
>
> Loris
>
> --
> This signature is currently under construction.
>
>
>

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

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

* Re: Import CSV file, remove columns, print table
  2019-09-13 13:33 Import CSV file, remove columns, print table Loris Bennett
  2019-09-13 13:42 ` John Kitchin
@ 2019-09-13 14:23 ` Fraga, Eric
  1 sibling, 0 replies; 6+ messages in thread
From: Fraga, Eric @ 2019-09-13 14:23 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

On Friday, 13 Sep 2019 at 15:33, Loris Bennett wrote:
> I can obviously write a source block of Python or R to do this, but
> can I manipulate the table more directly in Org?

You can refer to the first table from the second via the =remote()=
method.  See the info manual: (org) References.

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.2.4-401-gfabd6d

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

* Re: Import CSV file, remove columns, print table
  2019-09-13 13:42 ` John Kitchin
@ 2019-09-16 12:45   ` Loris Bennett
  2019-09-16 13:31     ` John Kitchin
  0 siblings, 1 reply; 6+ messages in thread
From: Loris Bennett @ 2019-09-16 12:45 UTC (permalink / raw)
  To: emacs-orgmode

Hi John,

Thanks - that's a nicely compact solution, albeit in the category
'source block' and in a language I'm not very skilled at :-)

I realise that I have slightly misstated the problem.  The ID in the
imported CSV is just a key from the database - I don't need it on the
list of participants.  However, it would be nice to number the
participants, who are sorted by surname.

How would I insert a column which just numbers the row?

Cheers,

Loris

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> You can do something like this:
>
> #+name: csv
> | ID | Name         | Titel / Title | Vorname / First Name | Nachname / Surname | Institution           |
> |  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple              | Universität zum Apfel |
> |  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne              | Pear University       |
> |  3 | Carol Carrot | Prof.         | Carol                | Carrot             | University of Veg     |
>
> #+BEGIN_SRC emacs-lisp :var data=csv
> (let ((table (mapcar (lambda (row) (list (nth 0 row) (nth 4 row) (nth 3 row))) data)))
>   (setf (car table) (append (car table) '("Signature")))
>   table) 
> #+END_SRC
>
> #+RESULTS:
> | ID | Nachname / Surname | Vorname / First Name | Signature |
> |  1 | Apple              | Alice                |           |
> |  2 | Birne              | Bob                  |           |
> |  3 | Carrot             | Carol                |           |
>
> 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
>
> On Fri, Sep 13, 2019 at 9:36 AM Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>
>  Hi,
>
>  I want to create a list of participants of an event which people can
>  sign, so that I can record who actually turned up.
>
>  From the registration website I can download a CSV file and import it
>  into and org file:
>
>  | ID | Name         | Titel / Title | Vorname / First Name | Nachname / Surname | Institution           |
>  |  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple              | Universität zum Apfel |
>  |  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne              | Pear University       |
>  |  3 | Carol Carrot | Prof.         | Carol                | Carrot             | University of Veg     |
>
>  I would like to reduce this to
>
>  | ID | Nachname / Surname | Vorname / First Name | Signature |
>  |  1 | Apple              | Alice                |           |
>  |  2 | Birne              | Bob                  |           |
>  |  3 | Carrot             | Carol                |           |
>
>  and then print it out as a LaTeX table.
>
>  I can obviously write a source block of Python or R to do this, but can
>  I manipulate the table more directly in Org?
>
>  Cheers,
>
>  Loris
>
>  -- 
>  This signature is currently under construction.
>
-- 
Dr. Loris Bennett (Mr.)
ZEDAT, Freie Universität Berlin         Email loris.bennett@fu-berlin.de

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

* Re: Import CSV file, remove columns, print table
  2019-09-16 12:45   ` Loris Bennett
@ 2019-09-16 13:31     ` John Kitchin
  2019-09-17 10:02       ` Loris Bennett
  0 siblings, 1 reply; 6+ messages in thread
From: John Kitchin @ 2019-09-16 13:31 UTC (permalink / raw)
  To: Loris Bennett; +Cc: org-mode-email

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

Here is another 'source block' solution, this time in python. You could so
something  similar in elisp. Here I use the library of babel approach so
you can call it wherever you want.



#+name: csv
| ID | Name         | Titel / Title | Vorname / First Name | Nachname /
Surname | Institution           |
|  3 | Carol Carrot | Prof.         | Carol                | Carrot
    | University of Veg     |
|  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple
     | Universität zum Apfel |
|  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne
     | Pear University       |


See https://orgmode.org/worg/org-contrib/babel/library-of-babel.html

#+name: signature-table
#+BEGIN_SRC python  :var data=csv :results value raw
results = [[surname, firstname, ""] for _, _, _, firstname, surname, _ in
data[1:]]

sorted_results = sorted(results,key=lambda row: row[1])

sorted_results = [[i + 1] + result for i, result in
enumerate(sorted_results)]

import tabulate
return tabulate.tabulate(sorted_results, ['#', 'Surname', 'First name',
'Signature'], tablefmt='orgtbl')
#+END_SRC



#+call: signature-table(data=csv)

#+RESULTS:
| # | Surname | First name | Signature |
|---+---------+------------+-----------|
| 1 | Apple   | Alice      |           |
| 2 | Birne   | Bob        |           |
| 3 | Carrot  | Carol      |           |


-----------------------------------
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



On Mon, Sep 16, 2019 at 8:48 AM Loris Bennett <loris.bennett@fu-berlin.de>
wrote:

> Hi John,
>
> Thanks - that's a nicely compact solution, albeit in the category
> 'source block' and in a language I'm not very skilled at :-)
>
> I realise that I have slightly misstated the problem.  The ID in the
> imported CSV is just a key from the database - I don't need it on the
> list of participants.  However, it would be nice to number the
> participants, who are sorted by surname.
>
> How would I insert a column which just numbers the row?
>
> Cheers,
>
> Loris
>
> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
> > You can do something like this:
> >
> > #+name: csv
> > | ID | Name         | Titel / Title | Vorname / First Name | Nachname /
> Surname | Institution           |
> > |  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple
>         | Universität zum Apfel |
> > |  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne
>         | Pear University       |
> > |  3 | Carol Carrot | Prof.         | Carol                | Carrot
>        | University of Veg     |
> >
> > #+BEGIN_SRC emacs-lisp :var data=csv
> > (let ((table (mapcar (lambda (row) (list (nth 0 row) (nth 4 row) (nth 3
> row))) data)))
> >   (setf (car table) (append (car table) '("Signature")))
> >   table)
> > #+END_SRC
> >
> > #+RESULTS:
> > | ID | Nachname / Surname | Vorname / First Name | Signature |
> > |  1 | Apple              | Alice                |           |
> > |  2 | Birne              | Bob                  |           |
> > |  3 | Carrot             | Carol                |           |
> >
> > 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
> >
> > On Fri, Sep 13, 2019 at 9:36 AM Loris Bennett <
> loris.bennett@fu-berlin.de> wrote:
> >
> >  Hi,
> >
> >  I want to create a list of participants of an event which people can
> >  sign, so that I can record who actually turned up.
> >
> >  From the registration website I can download a CSV file and import it
> >  into and org file:
> >
> >  | ID | Name         | Titel / Title | Vorname / First Name | Nachname /
> Surname | Institution           |
> >  |  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple
>         | Universität zum Apfel |
> >  |  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne
>         | Pear University       |
> >  |  3 | Carol Carrot | Prof.         | Carol                | Carrot
>          | University of Veg     |
> >
> >  I would like to reduce this to
> >
> >  | ID | Nachname / Surname | Vorname / First Name | Signature |
> >  |  1 | Apple              | Alice                |           |
> >  |  2 | Birne              | Bob                  |           |
> >  |  3 | Carrot             | Carol                |           |
> >
> >  and then print it out as a LaTeX table.
> >
> >  I can obviously write a source block of Python or R to do this, but can
> >  I manipulate the table more directly in Org?
> >
> >  Cheers,
> >
> >  Loris
> >
> >  --
> >  This signature is currently under construction.
> >
> --
> Dr. Loris Bennett (Mr.)
> ZEDAT, Freie Universität Berlin         Email loris.bennett@fu-berlin.de
>
>
>

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

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

* Re: Import CSV file, remove columns, print table
  2019-09-16 13:31     ` John Kitchin
@ 2019-09-17 10:02       ` Loris Bennett
  0 siblings, 0 replies; 6+ messages in thread
From: Loris Bennett @ 2019-09-17 10:02 UTC (permalink / raw)
  To: emacs-orgmode

Hi John,

Thanks, that's great.  

To get horizontal lines between each participant so that there is a nice
box for the signatures I tried

  return tabulate.tabulate(sorted_results, tablefmt='grid')

This works, but then the 

  #+ATTR_LaTeX: :environment longtable :align |r|l|l|p{8cm}|

seems to be ignored.

Is it possible to tweak the output for 'orgtbl' to insert hlines?

The other solution of course would be to not use 'tabulate' but generate
the table explicitly.

Cheers,

Loris


John Kitchin <jkitchin@andrew.cmu.edu> writes:

> Here is another 'source block' solution, this time in python. You
> could so something similar in elisp. Here I use the library of babel
> approach so you can call it wherever you want.
>
> #+name: csv
> | ID | Name         | Titel / Title | Vorname / First Name | Nachname / Surname | Institution           |
> |  3 | Carol Carrot | Prof.         | Carol                | Carrot             | University of Veg     |
> |  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple              | Universität zum Apfel |
> |  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne              | Pear University       |
>
> See https://orgmode.org/worg/org-contrib/babel/library-of-babel.html
>
> #+name: signature-table
> #+BEGIN_SRC python  :var data=csv :results value raw
> results = [[surname, firstname, ""] for _, _, _, firstname, surname, _ in data[1:]]
>
> sorted_results = sorted(results,key=lambda row: row[1])
>
> sorted_results = [[i + 1] + result for i, result in enumerate(sorted_results)]
>
> import tabulate
> return tabulate.tabulate(sorted_results, ['#', 'Surname', 'First name', 'Signature'], tablefmt='orgtbl')
> #+END_SRC
>
> #+call: signature-table(data=csv)
>
> #+RESULTS:
> | # | Surname | First name | Signature |
> |---+---------+------------+-----------|
> | 1 | Apple   | Alice      |           |
> | 2 | Birne   | Bob        |           |
> | 3 | Carrot  | Carol      |           |
>
> -----------------------------------
> 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
>
> On Mon, Sep 16, 2019 at 8:48 AM Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>
>  Hi John,
>
>  Thanks - that's a nicely compact solution, albeit in the category
>  'source block' and in a language I'm not very skilled at :-)
>
>  I realise that I have slightly misstated the problem.  The ID in the
>  imported CSV is just a key from the database - I don't need it on the
>  list of participants.  However, it would be nice to number the
>  participants, who are sorted by surname.
>
>  How would I insert a column which just numbers the row?
>
>  Cheers,
>
>  Loris
>
>  John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>  > You can do something like this:
>  >
>  > #+name: csv
>  > | ID | Name         | Titel / Title | Vorname / First Name | Nachname / Surname | Institution           |
>  > |  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple              | Universität zum Apfel |
>  > |  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne              | Pear University       |
>  > |  3 | Carol Carrot | Prof.         | Carol                | Carrot             | University of Veg     |
>  >
>  > #+BEGIN_SRC emacs-lisp :var data=csv
>  > (let ((table (mapcar (lambda (row) (list (nth 0 row) (nth 4 row) (nth 3 row))) data)))
>  >   (setf (car table) (append (car table) '("Signature")))
>  >   table) 
>  > #+END_SRC
>  >
>  > #+RESULTS:
>  > | ID | Nachname / Surname | Vorname / First Name | Signature |
>  > |  1 | Apple              | Alice                |           |
>  > |  2 | Birne              | Bob                  |           |
>  > |  3 | Carrot             | Carol                |           |
>  >
>  > 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
>  >
>  > On Fri, Sep 13, 2019 at 9:36 AM Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>  >
>  >  Hi,
>  >
>  >  I want to create a list of participants of an event which people can
>  >  sign, so that I can record who actually turned up.
>  >
>  >  From the registration website I can download a CSV file and import it
>  >  into and org file:
>  >
>  >  | ID | Name         | Titel / Title | Vorname / First Name | Nachname / Surname | Institution           |
>  >  |  1 | Alice Apple  | Fr./Ms.       | Alice                | Apple              | Universität zum Apfel |
>  >  |  2 | Bob Birne    | Hr./Mr.       | Bob                  | Birne              | Pear University       |
>  >  |  3 | Carol Carrot | Prof.         | Carol                | Carrot             | University of Veg     |
>  >
>  >  I would like to reduce this to
>  >
>  >  | ID | Nachname / Surname | Vorname / First Name | Signature |
>  >  |  1 | Apple              | Alice                |           |
>  >  |  2 | Birne              | Bob                  |           |
>  >  |  3 | Carrot             | Carol                |           |
>  >
>  >  and then print it out as a LaTeX table.
>  >
>  >  I can obviously write a source block of Python or R to do this, but can
>  >  I manipulate the table more directly in Org?
>  >
>  >  Cheers,
>  >
>  >  Loris
>  >
>  >  -- 
>  >  This signature is currently under construction.
>  >
>  -- 
>  Dr. Loris Bennett (Mr.)
>  ZEDAT, Freie Universität Berlin         Email loris.bennett@fu-berlin.de
>
-- 
Dr. Loris Bennett (Mr.)
ZEDAT, Freie Universität Berlin         Email loris.bennett@fu-berlin.de

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

end of thread, other threads:[~2019-09-17 10:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-13 13:33 Import CSV file, remove columns, print table Loris Bennett
2019-09-13 13:42 ` John Kitchin
2019-09-16 12:45   ` Loris Bennett
2019-09-16 13:31     ` John Kitchin
2019-09-17 10:02       ` Loris Bennett
2019-09-13 14:23 ` Fraga, Eric

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).