jupyter server dfdata.to_clipboard from remote to local machine. how?

巧了我就是萌 提交于 2019-12-23 10:12:45

问题


I have a dataframe say dfdata in a jupyter server notebook running on a remote machine).

I want to access the dataframe in the remote machine memory to my local machine, say to paste the dfdata to Excel.

Normally (when the notebook server is running locally), I do dfdata.to_clipboard() to copy the dataframe to clipboard and now able to paste it to Excel.

However, since the dfdata is now on the remote machine, the dfdata.to_clipboard() does not have the copy of the dataframe in clipboard.

How to make this work, i.e. copy paste dataframe from remote machine to locally running Excel, Textfile, etc.? Any alternative methods, if to_clipboard() by design will not work across remote server due to any security restrictions / limitations.


回答1:


I wrote a Jupyter nbextension to do this (installation instructions in the README).

It overwrites Panda's pandas.io.clipboard.copy & pandas.io.clipboard.clipboard_set (which is an embedded copy of pyperclip) to send messages to the Jupyter frontend via the Comm mechanism. I had to add a simple bootstrap-based UI that pops up when the client-side JS receives a message, as browsers won't let you push data onto the system clipboard without explicit user interaction (security!).




回答2:


If you have another terminal session connected to the same remote server, you can try getting the clipboard system to output to the terminal.

I tried xclip -o in another ssh session (after calling df.to_clipboard() in the notebook) and it printed the contents of my DataFrame to the terminal. I was able to copy that text and paste it to Google Sheets successfully, split correctly into columns.

It may depend on what's installed on the server. There is apparently another clipboard system called xsel, but xclip worked for me on Ubuntu Server 16.04.



来源:https://stackoverflow.com/questions/46547299/jupyter-server-dfdata-to-clipboard-from-remote-to-local-machine-how

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!