0
0
Snowflakecloud~5 mins

DataFrame API in Snowpark in Snowflake - Commands & Configuration

Choose your learning style9 modes available
Introduction
Working with large data sets inside Snowflake can be slow and complex if you use SQL alone. The DataFrame API in Snowpark lets you write simple code to manipulate data like a spreadsheet, but it runs fast inside Snowflake without moving data around.
When you want to process data inside Snowflake using simple code instead of complex SQL queries.
When you need to filter, group, or transform large tables without exporting data.
When you want to build data pipelines that run close to your data for speed and security.
When you prefer programming with familiar DataFrame operations like select, filter, and join.
When you want to chain multiple data operations in a clear and readable way.
Commands
Connect to Snowflake using SnowSQL CLI with your account, user, warehouse, database, and schema to run commands.
Terminal
snowsql -a myaccount -u myuser -w mywarehouse -d mydatabase -s public
Expected OutputExpected
Welcome to SnowSQL! You are now connected to Snowflake.
-a - Specifies the Snowflake account name
-u - Specifies the username
-w - Specifies the warehouse to use
-d - Specifies the database to use
-s - Specifies the schema to use
Run a Python script that uses Snowpark DataFrame API to load a table, filter rows, and show results.
Terminal
python3 snowpark_dataframe_example.py
Expected OutputExpected
id | name | age ---+---------+---- 3 | Charlie | 35
Key Concept

If you remember nothing else from this pattern, remember: Snowpark DataFrame API lets you write simple code to process data inside Snowflake efficiently without moving data out.

Code Example
Snowflake
from snowflake.snowpark import Session

connection_parameters = {
    "account": "myaccount",
    "user": "myuser",
    "password": "mypassword",
    "warehouse": "mywarehouse",
    "database": "mydatabase",
    "schema": "public"
}

session = Session.builder.configs(connection_parameters).create()

# Load table as DataFrame
people_df = session.table("people")

# Filter rows where age > 30
filtered_df = people_df.filter(people_df["age"] > 30)

# Show results
filtered_df.show()

session.close()
OutputSuccess
Common Mistakes
Trying to run Snowpark DataFrame code without setting up the Snowflake connection properly.
The code cannot connect to Snowflake, so it fails to load or process data.
Always configure your Snowflake account, user, warehouse, database, and schema correctly before running Snowpark code.
Using DataFrame operations without calling collect() or show() to get results.
DataFrame operations are lazy and do not execute until you ask for results, so no output appears.
Use collect() or show() methods to trigger execution and see data.
Summary
Connect to Snowflake using SnowSQL or Snowpark session with correct credentials.
Use Snowpark DataFrame API to load tables and apply filters or transformations.
Call show() or collect() to execute and view the results inside Snowflake.