emacs-jupyter / jupyter

An interface to communicate with Jupyter kernels.
GNU General Public License v3.0
932 stars 92 forks source link

Support pandas DataFrames #88

Closed qleguennec closed 5 years ago

qleguennec commented 5 years ago

I would like to output pandas DataFrames objects in org-tables format See:

#+BEGIN_SRC jupyter-python :session py :async yes :display text/plain
  data = %sql select * from actor where first_name like 'E%'
  dataframe = data.DataFrame()
  dataframe
#+END_SRC

#+RESULTS:
:RESULTS:
:  * postgresql://admin:***@localhost/dvdrental
: 7 rows affected.
:    actor_id first_name  last_name             last_update
: 0         3         Ed      Chase 2013-05-26 14:47:57.620
: 1        22      Elvis       Marx 2013-05-26 14:47:57.620
: 2        93      Ellen    Presley 2013-05-26 14:47:57.620
: 3       136         Ed  Mansfield 2013-05-26 14:47:57.620
: 4       139       Ewan    Gooding 2013-05-26 14:47:57.620
: 5       148      Emily        Dee 2013-05-26 14:47:57.620
: 6       179         Ed    Guiness 2013-05-26 14:47:57.620
:END:
dcherian commented 5 years ago

See https://bitbucket.org/astanin/python-tabulate .

I have trouble getting it to output in a format that I can export easily though. The output keeps getting wrapped in an example block.

nnicandro commented 5 years ago

Using tabulate is the way to go here since emacs-jupyter only has access to the mimetype information of the results, e.g. if it is html or png. If you look at the last tip in https://github.com/gregsexton/ob-ipython/blob/7147455230841744fb5b95dcbe03320313a77124/README.org#tips-and-tricks, you can get org-mode table output for dataframes.

qleguennec commented 5 years ago

@dzop Thanks, that works.