Tuesday, December 25, 2018

How to create a new Notebook in Databricks?



Notebook is the place where you write code in Python, Scala, SQL or R. In a notebook you can write a block in Python and other block in Scala or any other language. During run time code the code executes and shows the output regardless on the language its written.


You can execute your notebook step by step by clicking on “Run” option in each cell or you can run the whole notebook by clicking on “RullAll” at the top.
Ensure you have attached a cluster before click on “Run” icon.



Steps to create a new Notebook


Step 1:  Login to Databricks account







Step 2: You will get “Welcome to databricks” screen






Step 3: Click on “Workspace”, then “Create” and “Notebook”.










Step 4: Give the Notebook name and choose your Language in which you are planning to write code.





Step 5: Click on Detached dropdown and Attach your cluster. In below example “MyClusterOne” is the cluster name.




Step 6: You can see the cluster is added to the notebook.






Step 7:  Now, write code in your Notebook. Please find sample python program (printing “Hello World” text). Click on “Run Cell” to execute the program.







Step 8: Below program finds sum and average salaries.




Step 9: You can add new cells by clicking on “+”





Step 10: From document perspective you can write comments in the Cell as shown below:









Step 11: You can run all the code in a Notebook by clicking on “Run All” icon.





Step 12: Please find sample code written in multiple languages in a single workbook.




sample SQL code in same notebook





No comments:

Post a Comment