From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dov Grobgeld Subject: org-mode and python pandas Date: Fri, 28 Jun 2013 08:26:45 +0300 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsRCq-0006vL-JS for emacs-orgmode@gnu.org; Fri, 28 Jun 2013 01:26:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UsRCp-0001RF-8F for emacs-orgmode@gnu.org; Fri, 28 Jun 2013 01:26:48 -0400 Received: from mail-wi0-x230.google.com ([2a00:1450:400c:c05::230]:49273) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsRCp-0001R9-1E for emacs-orgmode@gnu.org; Fri, 28 Jun 2013 01:26:47 -0400 Received: by mail-wi0-f176.google.com with SMTP id ey16so351735wid.3 for ; Thu, 27 Jun 2013 22:26:45 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode Has anyone used org-mode with the python pandas package? Pandas is in a certain way an alternative to R, but with the (for me) familiar syntax of python. See: http://pandas.pydata.org/ Pandas is very much built to be used interactively, and it outputs its data in space separated tabular format. E.g. in ipython: In [1]: import pandas as pd In [2]: import numpy as np In [3]: pd.DataFrame(np.random.random((4,3)), columns=['A','B','C']) Out[3]: A B C 0 0.628365 0.424279 0.619791 1 0.799666 0.527572 0.132928 2 0.837255 0.138906 0.408233 3 0.388080 0.146212 0.575346 Unfortunately this doesn't output as nicely when used from org-mode: #+BEGIN_SRC python import pandas as pd import numpy as np return pd.DataFrame(np.random.random((4,3)), columns=list('ABC')) #+END_SRC #+RESULTS: : A B C : 0 0.827817 0.664009 0.089161 : 1 0.170031 0.729214 0.110918 : 2 0.575918 0.863924 0.757536 : 3 0.682722 0.774445 0.992041 while I would like to have: | | A | B | C | |---+----------+----------+----------| | 0 | 0.827817 | 0.664009 | 0.089161 | | 1 | 0.170031 | 0.729214 | 0.110918 | | 2 | 0.575918 | 0.863924 | 0.757536 | | 3 | 0.682722 | 0.774445 | 0.992041 | The question is how to get this? Here are a few ideas: 1. Write a general filter in the org-mode elisp than uses heuristics to recognize ascii aligned tables and change these to org-tables. 2. Add to pandas the option of globally influencing the text formatting so that it outputs something more parsable by org-mode. 3. Create a special language "pandas" that recognize the ascii aligned tables and saves the need to import pandas and np? 4. And the obvious approach of writing a python function that writes a org-mode parsable table and always call it as part of the return. Which is the preferable approach? Any other ideas? Regards, Dov