Get started: Query and visualize data from a notebook

This get started article walks you through using an Azure Databricks notebook to query sample data stored in Unity Catalog using SQL, Python, Scala, and R and then visualize the query results in the notebook.

Requirements

To complete the tasks in this article, you must meet the following requirements:

Step 1: Create a new notebook

To create a notebook in your workspace:

  1. Click New Icon New in the sidebar, then click Notebook.
  2. On the Create Notebook page:
    • Specify a unique name for your notebook.
    • Set the default language for your notebook and then click Confirm if prompted.
    • Use the Connect dropdown menu to select a compute resource. To create a new compute resource, see Use compute.

To learn more about creating and managing notebooks, see Manage notebooks.

Step 2: Query a table

Query the samples.nyctaxi.trips table in Unity Catalog using the language of your choice.

  1. Copy and paste the following code into the new empty notebook cell. This code displays the results from querying the samples.nyctaxi.trips table in Unity Catalog.

    SQL

    SELECT * FROM samples.nyctaxi.trips
    

    Python

    display(spark.read.table("samples.nyctaxi.trips"))
    

    Scala

    display(spark.read.table("samples.nyctaxi.trips"))
    

    R

    library(SparkR)
    display(sql("SELECT * FROM samples.nyctaxi.trips"))
    
  2. Press Shift+Enter to run the cell and then move to the next cell.

    The query results appear in the notebook.

Step 3: Display the data

Display the average fare amount by trip distance, grouped by the pickup zip code.

  1. Next to the Table tab, click + and then click Visualization.

    The visualization editor displays.

  2. In the Visualization Type drop-down, verify that Bar is selected.

  3. Select fare_amount for the X column.

  4. Select trip_distance for the Y column.

  5. Select Average as the aggregation type.

  6. Select pickup_zip as the Group by column.

    Bar chart

  7. Click Save.

Next steps