---
title: "Tutorial: Query and visualize data from a notebook"
description: Learn data science basics on Databricks. Using a notebook, query and visualize data stored in Unity Catalog by using SQL, Python, Scala, and R.
canonical_url: https://docs.databricks.com/aws/en/getting-started/quick-start
---

# Tutorial: Query and visualize data from a notebook

This tutorial walks you through using a 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.

> [!TIP]
>
> Tell [Genie Code](https://docs.databricks.com/aws/en/genie-code/index.md) to do this for you:
>
> ```
> Create a new notebook that queries @samples.nyctaxi.trips and displays a bar chart showing the average fare amount by trip distance, grouped by the pickup zip code.
> ```

## Requirements

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

* Your workspace must have [Unity Catalog](https://docs.databricks.com/aws/en/data-governance/unity-catalog/index.md) enabled. For information on getting started with Unity Catalog, see [Get started with Unity Catalog](https://docs.databricks.com/aws/en/data-governance/unity-catalog/get-started.md).
* You must have permission to use an existing compute resource or create a new compute resource. See [Compute](https://docs.databricks.com/aws/en/compute/index.md) or see your Databricks administrator.

## <a id="create-notebook" />Step 1: Create a new notebook

To create a notebook in your workspace, click ![New Icon](https://docs.databricks.com/aws/en/images/icons/create-icon.png) **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 Databricks notebooks](https://docs.databricks.com/aws/en/notebooks/notebooks-manage.md).

## Step 2: Query a table

Query the `samples.nyctaxi.trips` table in Unity Catalog using the language of your choice. This table is one of the [sample datasets](https://docs.databricks.com/aws/en/discover/databricks-datasets.md#nyctaxi) included in the `samples` catalog.

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

   ```sql
   SELECT * FROM samples.nyctaxi.trips
   ```

   ### Python

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

   ### Scala

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

   ### R

   ```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](https://docs.databricks.com/aws/en/images/notebooks/trip_distance.png)

7. Click **Save**.

## Next steps

* To learn about adding data from CSV file to Unity Catalog and visualize data, see [Tutorial: Import and visualize CSV data from a notebook](https://docs.databricks.com/aws/en/getting-started/import-visualize-data.md).
* To learn how to load data into Databricks using Apache Spark, see [Tutorial: Load and transform data using Apache Spark DataFrames](https://docs.databricks.com/aws/en/getting-started/dataframes.md).
* To learn more about ingesting data into Databricks, see [Ingest with SQL and Spark APIs](https://docs.databricks.com/aws/en/ingestion/index.md).
* To learn more about querying data with Databricks, see [Query data](https://docs.databricks.com/aws/en/query/index.md).
* To learn more about visualizations, see [Visualizations in Databricks notebooks and SQL editor](https://docs.databricks.com/aws/en/visualizations/index.md).
* To learn more about exploratory data analysis (EDA) techniques, see [Tutorial: EDA techniques using Databricks notebooks](https://docs.databricks.com/aws/en/notebooks/eda-tutorial.md).
