Visualize query results

Use this quickstart to run SQL and visualize your results in a BigQuery notebook:

  • Run a query using the bigquery-public-data.ml_datasets.penguins public dataset.
  • Use a SQL cell to iterate on your query results.
  • Use a visualization cell to display the average culmen length and depth of female penguins for each species.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  4. Verify that billing is enabled for your Google Cloud project.

  5. Verify that the BigQuery API is enabled.

    Enable the API

    If you created a new project, the BigQuery API is automatically enabled.

Required permissions

To create and run notebooks, you need the following Identity and Access Management (IAM) roles:

Create a notebook

Follow the instructions in Create a notebook from the BigQuery editor to create a new notebook.

Run a query

To run a SQL query in a notebook, follow these steps:

  1. To create a new SQL cell in your notebook, click SQL.

  2. Enter the following query:

    SELECT * FROM `bigquery-public-data.ml_datasets.penguins`;
    
  3. Click Run cell.

    The results of the query are automatically saved in a DataFrame called df.

  4. Create another SQL cell and change the title to female_penguins.

  5. Enter the following query, which references the DataFrame you just created and filters the results to only include female penguins:

    SELECT * FROM {df} WHERE sex = 'FEMALE';
    
  6. Click Run cell.

    The results of the query are automatically saved in a DataFrame called female_penguins.

Visualize results

  1. To create a new visualization cell in your notebook, click Visualization.

  2. Click Choose a dataframe and then select female_penguins.

    A chart interface appears.

  3. Click Scatter chart to open a chart menu, then select the Vertical bar chart.

  4. In the Metric section, check that culmen_length_mm and culmen_depth_mm appear. If a metric is missing, click Add metric and select it. To remove a metric, hold the pointer over the metric name and then click Close.

  5. For each metric, click Edit. For Aggregation select Average.

Bar chart showing visualization

Clean up

The easiest way to eliminate billing is to delete the project that you created for the tutorial.

To delete the project:

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next