Share via

Passing variable in notebook

Anshal 2,251 Reputation points
2022-02-25T12:16:55.007+00:00

Hi friends I have a count variable and want to pass this in another notebook I am able call this and parameter this but it coming as string and the variable count value is not coming help me please

Azure Databricks
Azure Databricks

An Apache Spark-based analytics platform optimized for Azure.

Azure Data Factory
Azure Data Factory

An Azure service for ingesting, preparing, and transforming data at scale.


Answer accepted by question author

AnnuKumari-MSFT 34,571 Reputation points Microsoft Employee Moderator
2022-03-01T14:04:06.157+00:00

Hi @Anshal ,
Thankyou for using Microsoft Q&A platform and posting your query.

As I understand your query, it looks to me like you have two notebooks , in first notebook you have a variable which holds some count value(int). You want to pass this variable value into another notebook. Please let me know if my understanding is wrong.

You can make use of mssparkutils.notebook.exit("value string") command in pyspark which helps to exit a notebook with a value.

Please refer to the following article for more details: Exit a notebook

I tried to repro your scenario using Azure Synapse analytics. Same can be done in even databricks.

In Notebook1 :

  1. I created a dataframe with two rows.
  2. Got the count of rows in variable called 'var1'
  3. Exited the notebook with value 'var1'

178926-image.png

In Notebook2:

  1. Running Notebook 1 using mssparkutils.notebook.run("Notebook name") . Please refer to : Reference a Notebook
  2. Using the variable from Notebook 1 inside Notebook 2

178829-image.png

Hope this will help. Please let us know if any further queries.

------------------------------

  • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
    Original posters help the community find answers faster by identifying the correct answer. Here is how
  • Want a reminder to come back and check responses? Here is how to subscribe to a notification
  • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.