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.

๐ชStep-by-Step: How to Create and Use Notebooks in Databricks
Step 1: Create a New Notebook
- Either click on New in Welcome Page or In your Databricks workspace, click on the Workspace tab on the left sidebar.
- Click on the Create button and select Notebook.
- Enter a name for your notebook.
- Choose the default language (Python, SQL, Scala, or R).
- Click Create.


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

Step 3: Write and Execute Code
- 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")

2.Execute the cell by pressing Shift + Enter or clicking the Run button.
Step 4: Display Data
- To display a Data Frame, use the display function:
%python
display(df)

Step 5: To Print Schema of Data
- Use PrintSchema function
%python
df.printSchema()

Step 6: We can use Markdown cell to give heading
- Click on + and then Text to select Markdown cell

Step 7: Rename the Notebook
- Double click on top left to rename the notebook and you are all set as there is no need to save it manually

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