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, click New Icon New in the sidebar, and then click Notebook. A blank notebook opens in the workspace.

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