Animesh Anand
Animesh Anand

Reputation: 11

Accessing dataframes in different notebooks in google data lab

I am using google cloud data lab, and I have several data frames in different notebooks. Is there any way to access all these data frames in one notebook? I use SQL and python for writing the codes.

The data frames are the base tables for user engagement in an android app. These base tables are user data, experience data, and session data.

Now, if I want to generate an analytics table that uses all these base tables( in different notebooks), then is there a way to use these tables in a different notebook

Upvotes: 1

Views: 432

Answers (1)

Anthonios Partheniou
Anthonios Partheniou

Reputation: 1709

To access functions/variables from other notebooks in Google Cloud Datalab, simply run the other notebooks from your current notebook using the line magic command %run

For example:

  1. Create a notebook called 'notebook_a.ipynb'
  2. In the notebook, enter the following in an empty cell: variable_a = 5
  3. Save the notebook
  4. Open a different notebook in the same directory.
  5. Execute the following line magic command in a cell from the notebook in step 4.%run 'notebook_a.ipynb'
  6. You should be able to see the value of variable_a which exists in another notebook.

Adjust the path accordingly if the notebook is not the same directory with %run <relative path to notebook>

I posted a similar answer in a related Stack Overflow post.

Note: This does not work if you are running Datalab on Google Cloud Platform.

Upvotes: 1

Related Questions