Sign inGet started
← Back to all guides

How to export results to CSV in BigQuery

By Nick Barth

Updated on March 6, 2024

In Deepnote, exporting your BigQuery results to a CSV file involves a few straightforward steps. First, run your query in BigQuery and ensure the results are exactly as needed. Then, use the `to_csv` method available in the Pandas library to write the data to a CSV file. Here is a basic code snippet you'd use in a Deepnote notebook cell:

from import bigquery
⁠import pandas as pd

Construct a BigQuery client object.

client = bigquery.Client()

Perform your query.

QUERY = """
⁠    SELECT * FROM `your-project.your_dataset.your_table`
⁠query_job = client.query(QUERY)

Convert the query results to a pandas DataFrame

df = query_job.to_dataframe()

Write the DataFrame to a CSV file

df.to_csv('your_results.csv', index=False)

Replace the `QUERY` string with your actual query and set the appropriate project, dataset, and table information. This code will write the results of the query to a CSV file named `'your_results.csv'` without the row indices. Save the notebook and run the cell to perform the operation. The CSV file will be created in the file system of your Deepnote project, and you can download it directly from there.

That’s it, time to try Deepnote

Get started – it’s free
Book a demo



  • Integrations
  • Pricing
  • Documentation
  • Changelog
  • Security




  • Privacy
  • Terms

© Deepnote