Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share data between IPython Notebooks

If I have several IPython notebooks running on the same server. Is there any way to share data between them? For example, importing a variable from another notebook? Thanks!

like image 711
Kyle Siegel Avatar asked Jul 24 '15 23:07

Kyle Siegel


People also ask

How do I share my IPython notebook?

Sharing Locally You can export to a variety of formats from within the notebook by navigating to File -> Download As. You'll want to export your notebook as a Jupyter Interactive Notebook ( . ipynb file format) if you'd like the person you're sharing it with to interact with the notebook.

How do you link two Jupyter notebooks?

Running a Jupyter Notebook from Another Jupyter NotebookFrom the left Sidebar, select and right-click on the Jupyter notebook that has to be run from another notebook. From the context menu, select Copy Path. Open the Jupyter notebook from which you want to run another notebook. Click Run.


2 Answers

This works for me :

The %store command lets you pass variables between two different notebooks.

data = 'this is the string I want to pass to different notebook' %store data

Now, in a new notebook… %store -r data print(data) this is the string I want to pass to different notebook

I've successfully tested with sklearn dataset :

from sklearn import datasets  dataset = datasets.load_iris()  %store dataset 

in notebook to read data :

%store -r dataset 

src : https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/

like image 117
blue-sky Avatar answered Sep 20 '22 00:09

blue-sky


Notebooks in Jupyter Lab can share the same kernel. In your notebook you can choose the kernel of another notebook and variables from the other notebook will be available in both notebooks.

screenshot Jupyter Lab kernel selection popup

  1. Click on the button that describes your current kernel.
  2. Choose the kernel of the other notebook, whose variables you want to access.
like image 39
Stefan_EOX Avatar answered Sep 20 '22 00:09

Stefan_EOX