Using pandas via Jupyterhub

263 views
Skip to first unread message

Christian Prinoth

unread,
Feb 27, 2017, 5:15:05 AM2/27/17
to pyd...@googlegroups.com
I have successfully set up Jupyterhub at my organization, having users able to login with their AD user/pw, and then having access to a regular python environment. Using pandas works fine, as well as plotting via matplotlib and nbagg.

What I am missing is some way for users to get data from python to their local computers, i.e. exporting a dataframe. The to_clipboard method does not work (I guess it is pasting to the clipboard on the server?). Maybe there is some way that I can take a dataframe, create a csv and then download it?
The cumbersome way is to set up a shared network folder, have users save the data to a file on the server, and then get it from the share. But getting it directly as a download from the browser would be better, and some way leveraging the clipboard would be even more so.

Thanks for any suggestions!

--

Christian Prinoth

Joris Van den Bossche

unread,
Feb 27, 2017, 5:32:01 AM2/27/17
to PyData
The problem of getting data from the server to a local machine (or the other way around) is of course not specific to pandas, and it is probably best to have a general way for your users to do this (eg certain ssh client that can do file transfer if you want a GUI, ...).

But if you want something similar to `to_clipboard` for quickly getting some DataFrame content locally, you can also use `to_csv` without a path argument. This will output the actual csv concent in the notebook, which you can also copy and paste locally. Or other alternative is `to_string`.

Joris

--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christian Prinoth

unread,
Feb 27, 2017, 6:00:37 AM2/27/17
to pyd...@googlegroups.com
Hi, I have tried this, but whatever string format (and combination of delimiters) I "print" on the notebook can not be easily copied and pasted into an excel sheet.

--

Christian Prinoth

Pietro Battiston

unread,
Feb 27, 2017, 8:57:51 AM2/27/17
to pyd...@googlegroups.com
Il giorno lun, 27/02/2017 alle 11.14 +0100, Christian Prinoth ha
scritto:
> [...]
> What I am missing is some way for users to get data from python to
> their local computers, i.e. exporting a dataframe. The to_clipboard
> method does not work (I guess it is pasting to the clipboard on the
> server?). Maybe there is some way that I can take a dataframe, create
> a csv and then download it?
> The cumbersome way is to set up a shared network folder, have users
> save the data to a file on the server, and then get it from the
> share. But getting it directly as a download from the browser would
> be better, and some way leveraging the clipboard would be even more
> so.

This could certainly be done through some Jupyter widget, but I don't
know of any existing one.

This said, I never used Jupyterhub, but the plain Jupyter will provide
me, in the "/tree" page, with a list of files which includes non-
notebooks, also allowing me to download them. This is not optimal, but
probably better than setting up an ad hoc share...

Pietro

Christian Prinoth

unread,
Feb 27, 2017, 9:10:48 AM2/27/17
to pyd...@googlegroups.com
This suggestion is so obvious that I somehow have not thought about it!!

I was thinking about some convoluted JS solution, but this works very well, thanks

--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Christian Prinoth

Miki Tebeka

unread,
Feb 28, 2017, 12:03:53 AM2/28/17
to PyData
You can probably cook up something with qgrid (which uses SlickGrid) and some javascript like http://stackoverflow.com/questions/11503007/slickgrid-functions-for-csv-export

Dov Grobgeld

unread,
Feb 28, 2017, 2:19:32 AM2/28/17
to pyd...@googlegroups.com
It would be nice if Jupyter had something similar to IPython.display.image for providing a file download button, e.g. IPython.file.export(filename). This function should provide a download button.

I'll create a feature request for Jupyter for this.

Regards,
Dov


--

Dov Grobgeld

unread,
Feb 28, 2017, 2:31:08 AM2/28/17
to pyd...@googlegroups.com
I created the following issue on github: https://github.com/jupyter/notebook/issues/2236

Dov Grobgeld

unread,
Feb 28, 2017, 8:59:51 AM2/28/17
to pyd...@googlegroups.com
It turns out that this functionality already exists through IPython.display.FileLink(). Thus a downloadable file may be created through:

from IPython.display as FileLink
df = pd.DataFrame([[0,1],[2,3]],columns=['A','B']) # Create dataframe

# Save to filename and provide download link
df.to_csv('foo.csv')
FileLink('foo.csv')

The user may then download the file by right clicking on the filelink and chosing the save option.

Regards,
Dov

Christian Prinoth

unread,
Feb 28, 2017, 10:28:20 AM2/28/17
to pyd...@googlegroups.com
This is great, exactly what I needed, thanks!
--

Christian Prinoth
Reply all
Reply to author
Forward
0 new messages