cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Community Articles
Dive into a collaborative space where members like YOU can exchange knowledge, tips, and best practices. Join the conversation today and unlock a wealth of collective wisdom to enhance your experience and drive success.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Getting Started with Notebooks in Databricks

bhanu_gautam
Valued Contributor III

Databricks notebooks are a powerful tool for data scientists and engineers to collaborate, explore data, and build machine learning models. This guide will help you get started with creating and using notebooks in Databricks.

๐Ÿ““Why Use Databricks Notebooks?

  • Interactive Development: Write and execute code in real-time.
  • Collaboration: Share notebooks with your team and collaborate seamlessly.
  • Visualization: Easily visualize data with built-in charting tools.
  • Integration: Integrate with various data sources and libraries.

bhanu_gautam_0-1757091779506.png

๐ŸชœStep-by-Step: How to Create and Use Notebooks in Databricks

Step 1: Create a New Notebook

  1. Either click on New in Welcome Page or In your Databricks workspace, click on the Workspace tab on the left sidebar.
  2. Click on the Create button and select Notebook.
  3. Enter a name for your notebook.
  4. Choose the default language (Python, SQL, Scala, or R).
  5. Click Create.

bhanu_gautam_3-1757091812187.png

bhanu_gautam_4-1757091847706.jpeg

Step 2: Attach a Cluster

  1. In your new notebook, click on the Attach button at the top.
  2. Select an existing cluster or create a new one.
  3. Wait for the cluster to start and attach to your notebook.

bhanu_gautam_5-1757091871939.jpeg

Step 3: Write and Execute Code

  1. In a code cell, write your code. There are 4 languages which can be used, and we will use Python in this example and a sample table. For example, to read a table:
%python
df = spark.read.table("samples.accuweather.forecast_daily_calendar_imperial")

bhanu_gautam_6-1757091957142.png

2.Execute the cell by pressing Shift + Enter or clicking the Run button.

Step 4: Display Data

  1. To display a Data Frame, use the display function:
%python
display(df)

bhanu_gautam_7-1757092019039.png

Step 5: To Print Schema of Data

  1. Use PrintSchema function
%python
df.printSchema()

bhanu_gautam_8-1757092078221.png

Step 6: We can use Markdown cell to give heading

  1. Click on + and then Text to select Markdown cell

bhanu_gautam_9-1757092117192.png

Step 7: Rename the Notebook

  1. Double click on top left to rename the notebook and you are all set as there is no need to save it manually

bhanu_gautam_10-1757092158177.jpeg

Pro Tips for Using Databricks Notebooks

  • Use Markdown cells to add documentation and explanations.
  • Utilize Magic Commands (e.g., %sql, %md) to switch between languages.
  • Leverage Widgets to create interactive controls for your notebook.
  • Explore the Databricks Documentation for advanced features and best practices.

Final Thoughts

Databricks notebooks are an essential tool for data professionals. They provide an interactive and collaborative environment for data exploration, analysis, and machine learning. By following this guide, you can quickly get started with notebooks in Databricks and unlock their full potential.

Regards
Bhanu Gautam

Kudos are appreciated
2 REPLIES 2

Advika
Databricks Employee
Databricks Employee

Thanks for sharing @bhanu_gautam. This will surely help beginners get started with Databricks Notebooks.

bhanu_gautam
Valued Contributor III

Thank you @Advika 

Regards
Bhanu Gautam

Kudos are appreciated