Sign inGet started
← Back to all guides

How to export Snowflake query to Pandas dataframe

By Nick Barth

Updated on March 6, 2024

To export a query from Snowflake to a Pandas DataFrame in Python, you can use the `snowflake-connector-python` package. This allows you to fetch data directly into DataFrame format with just a few lines of code. Begin by installing the snowflake-connector with `pip install snowflake-connector-python`. Then, structure your script to connect to your Snowflake account using your credentials, execute the query, and fetch the results into a DataFrame:

import snowflake.connector

import pandas as pd

Establishing the Snowflake connection

conn = snowflake.connector.connect(
  user='<your_username>',
  password='<your_password>',
  account='<your_account_url>',
  warehouse='<your_warehouse>',
  database='<your_database>',
  schema='<your_schema>'
)

Execute a query and fetch the result into a pandas DataFrame

query = "SELECT * FROM YOUR_TABLE_NAME;"
cursor = conn.cursor()
cursor.execute(query)
df = pd.DataFrame(cursor.fetchall(), columns=[x[0] for x in cursor.description])

Always close the cursor and connection when done

cursor.close()
conn.close()

Replace the placeholder values with your actual Snowflake credentials and modify the query as per your requirements. After running this script, `df` will contain the result of the Snowflake query as a Pandas DataFrame.

That’s it, time to try Deepnote

Get started – it’s free
Book a demo

Footer

Product

  • Integrations
  • Pricing
  • Documentation
  • Changelog
  • Security

Company

Comparisons

Resources

  • Privacy
  • Terms

© Deepnote