Re: [O] getting an hline in a python generated table
Sorry about that. I switched out of Org mode in my email client so C-c C-c sent the email instead of executing the code block. I was mid-sentence... #+BEGIN_SRC python :results table :exports results from tabulate import tabulate import pandas as pd df = pd.DataFrame(np.random.rand(2,2), index=['foo','bar']) tab = tabulate(df, ['col1','col2'], tablefmt='orgtbl') print tab[1:-1] #+END_SRC #+RESULTS: I'm compensating for some bugs here. The tab[1:-1] is from, I think, tabulate, or perhaps IPython. I don't get results without this being a Since I use Org + IPython, I find that my On 2015-04-01 at 16:07, John Kitchin jkitc...@andrew.cmu.edu wrote: Hi everyone, In emacs-lisp, I can get a table as output that has a horizontal line in it like this: (append '((name scopus-id h-index n-docs n-citations)) '(hline) (some expression that generates a list)) The first row is header names, then a horizontal line, followed by a row for each thing of interest. This seems to work because the result is an emacs-lisp array. I cannot figure out if this is possible in a Python block though. So far my experiments have failed because I don't know how to make an hline symbol in a Python array. Any kind of string just shows as a row. Any thoughts on if this is possible? thanks, #+OPTIONS: tex:imagemagick #+OPTIONS: toc:0
Re: [O] getting an hline in a python generated table
I've been using the following to generate hline in Org Python blocks: #+BEGIN_SRC python :results table :exports results from tabulate import tabulate import pandas as pd df = pd.DataFrame(np.random.rand(2,2), index=['foo','bar']) tab = tabulate(df, ['col1','col2'], tablefmt='orgtbl') return tab[1:-1] #+END_SRC #+RESULTS: | | col1 | col2 | |-++--| | foo | 0.363568 | 0.647676 | | bar | 0.00663499 | 0.100717 | I'm compensating for some bugs here. The tab[1:-1] is from, I think, tabulate, or perhaps IPython. I don't get results without this being a Since I use Org + IPython, I find that my On 2015-04-01 at 16:07, John Kitchin jkitc...@andrew.cmu.edu wrote: Hi everyone, In emacs-lisp, I can get a table as output that has a horizontal line in it like this: (append '((name scopus-id h-index n-docs n-citations)) '(hline) (some expression that generates a list)) The first row is header names, then a horizontal line, followed by a row for each thing of interest. This seems to work because the result is an emacs-lisp array. I cannot figure out if this is possible in a Python block though. So far my experiments have failed because I don't know how to make an hline symbol in a Python array. Any kind of string just shows as a row. Any thoughts on if this is possible? thanks, #+OPTIONS: tex:imagemagick #+OPTIONS: toc:0
Re: [O] getting an hline in a python generated table
cool, thanks for the tip. I was not awware of that library. Ken Mankoff writes: Sorry about that. I switched out of Org mode in my email client so C-c C-c sent the email instead of executing the code block. I was mid-sentence... #+BEGIN_SRC python :results table :exports results :session from tabulate import tabulate import pandas as pd df = pd.DataFrame(np.random.rand(2,2), index=['foo','bar']) tab = tabulate(df, ['col1','col2'], tablefmt='orgtbl') tab[1:-1] #+END_SRC #+RESULTS: | | col1 | col2 | |-+--+--| | foo | 0.223272 | 0.433449 | | bar | 0.855854 | 0.13685 | I'm compensating for some bugs here. The tab[1:-1] is from, I think, tabulate, or perhaps IPython. I don't get results without this being a :session. If you don't use IPython/elpy in Org, then your final statement may need to be different (add a 'return'?) to get this to work. Hope this helps with w/ tables + headers, -k. -- 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
Re: [O] getting an hline in a python generated table
A simpler solution is to just use None, which gets automatically converted to an hline by org-babel: #+BEGIN_SRC python :return mytable NROWS, NCOLS = 6, 4 mytable = [] mytable.append(['A', 'B', 'C', 'D']) # Table header mytable.append(None) # hline for irow in range(NROWS): mytable.append([icol**irow for icol in range(NCOLS)]) mytable.append(None) # hline #+END_SRC #+RESULTS: | A | B | C | D | |---+---++-| | 1 | 1 | 1 | 1 | | 0 | 1 | 2 | 3 | | 0 | 1 | 4 | 9 | | 0 | 1 | 8 | 27 | | 0 | 1 | 16 | 81 | | 0 | 1 | 32 | 243 | |---+---++-| Will On Wed, Apr 1, 2015 at 2:07 PM, John Kitchin jkitc...@andrew.cmu.edu wrote: Hi everyone, In emacs-lisp, I can get a table as output that has a horizontal line in it like this: (append '((name scopus-id h-index n-docs n-citations)) '(hline) (some expression that generates a list)) The first row is header names, then a horizontal line, followed by a row for each thing of interest. This seems to work because the result is an emacs-lisp array. I cannot figure out if this is possible in a Python block though. So far my experiments have failed because I don't know how to make an hline symbol in a Python array. Any kind of string just shows as a row. Any thoughts on if this is possible? thanks, -- 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 -- Dr William Henney, Centro de Radioastronomía y Astrofísica, Universidad Nacional Autónoma de México, Campus Morelia
Re: [O] getting an hline in a python generated table
wow, that is some wizardry there! I did not know you could do a return value that way! or get an hline from None! thanks! William Henney writes: A simpler solution is to just use None, which gets automatically converted to an hline by org-babel: #+BEGIN_SRC python :return mytable NROWS, NCOLS = 6, 4 mytable = [] mytable.append(['A', 'B', 'C', 'D']) # Table header mytable.append(None) # hline for irow in range(NROWS): mytable.append([icol**irow for icol in range(NCOLS)]) mytable.append(None) # hline #+END_SRC #+RESULTS: | A | B | C | D | |---+---++-| | 1 | 1 | 1 | 1 | | 0 | 1 | 2 | 3 | | 0 | 1 | 4 | 9 | | 0 | 1 | 8 | 27 | | 0 | 1 | 16 | 81 | | 0 | 1 | 32 | 243 | |---+---++-| Will On Wed, Apr 1, 2015 at 2:07 PM, John Kitchin jkitc...@andrew.cmu.edu wrote: Hi everyone, In emacs-lisp, I can get a table as output that has a horizontal line in it like this: (append '((name scopus-id h-index n-docs n-citations)) '(hline) (some expression that generates a list)) The first row is header names, then a horizontal line, followed by a row for each thing of interest. This seems to work because the result is an emacs-lisp array. I cannot figure out if this is possible in a Python block though. So far my experiments have failed because I don't know how to make an hline symbol in a Python array. Any kind of string just shows as a row. Any thoughts on if this is possible? thanks, -- 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 -- 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
[O] getting an hline in a python generated table
Hi everyone, In emacs-lisp, I can get a table as output that has a horizontal line in it like this: (append '((name scopus-id h-index n-docs n-citations)) '(hline) (some expression that generates a list)) The first row is header names, then a horizontal line, followed by a row for each thing of interest. This seems to work because the result is an emacs-lisp array. I cannot figure out if this is possible in a Python block though. So far my experiments have failed because I don't know how to make an hline symbol in a Python array. Any kind of string just shows as a row. Any thoughts on if this is possible? thanks, -- 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
Re: [O] getting an hline in a python generated table
Hi John, John Kitchin jkitc...@andrew.cmu.edu writes: In emacs-lisp, I can get a table as output that has a horizontal line in it like this: (append '((name scopus-id h-index n-docs n-citations)) '(hline) (some expression that generates a list)) The first row is header names, then a horizontal line, followed by a row for each thing of interest. This seems to work because the result is an emacs-lisp array. I cannot figure out if this is possible in a Python block though. So far my experiments have failed because I don't know how to make an hline symbol in a Python array. Any kind of string just shows as a row. Any thoughts on if this is possible? I'd be lazy and just use the :post argument. So something like the following. I'm pretty sure I once wrote a :post function that took negative number (to add a final hline), but I couldn't find it... #+BEGIN_SRC python :post add-hline(tbl=*this*) return([ [a], [1], [2]]) #+END_SRC #+RESULTS: |---| | a | |---| | 1 | | 2 | #+name: add-hline #+BEGIN_SRC emacs-lisp :var tbl='((a) (b) (c)) hlines='(0 1) (loop for hline in (mapcar* '+ hlines (number-sequence 0 (length hlines))) do (setq tbl (append (subseq tbl 0 hline) '(hline) (subseq tbl hline tbl #+END_SRC Hope it helps, Rasmus -- With monopolies the cake is a lie!