0
0
Snowflakecloud~10 mins

Snowpark for Python basics in Snowflake - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Snowpark for Python basics
Start: Connect to Snowflake
Create Snowpark Session
Load Data into DataFrame
Transform Data (e.g., filter, select)
Show or Collect Results
End Session
This flow shows how to connect to Snowflake, create a Snowpark session, load data, transform it, and get results.
Execution Sample
Snowflake
from snowflake.snowpark import Session

session = Session.builder.configs({...}).create()
df = session.table('MY_TABLE')
df_filtered = df.filter(df['AGE'] > 30)
df_filtered.show()
Connects to Snowflake, loads a table, filters rows where AGE > 30, and shows the results.
Process Table
StepActionInput/ConditionResult/Output
1Create SessionConfigs providedSession object created
2Load TableTable name: MY_TABLEDataFrame with all rows from MY_TABLE
3Filter DataFrameCondition: AGE > 30New DataFrame with filtered rows
4Show DataFrameCall show()Prints filtered rows to console
5EndNo more actionsSession can be closed or reused
💡 All steps completed; data filtered and displayed successfully.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4
sessionNoneSession objectSession objectSession objectSession object
dfNoneNoneDataFrame with all MY_TABLE rowsDataFrame with all MY_TABLE rowsDataFrame with all MY_TABLE rows
df_filteredNoneNoneNoneDataFrame filtered AGE > 30DataFrame filtered AGE > 30
Key Moments - 3 Insights
Why do we create a session first before loading data?
The session connects your Python code to Snowflake. Without it, you cannot access tables or run queries. See execution_table step 1.
Does filtering change the original DataFrame?
No, filtering creates a new DataFrame with the filtered data. The original stays unchanged. See execution_table steps 2 and 3.
What does the show() method do?
It prints the DataFrame rows to the console for you to see. It does not return data to Python variables. See execution_table step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the state of 'df' after step 3?
ASession object
BDataFrame filtered with AGE > 30
CDataFrame with all rows from MY_TABLE
DNone
💡 Hint
Check the variable_tracker for 'df' after step 3.
At which step is the data actually filtered?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Look at the execution_table action descriptions.
If you skip creating the session, what happens?
AYou cannot connect to Snowflake
BYou can still load tables
CFiltering works but no data shows
Dshow() prints empty output
💡 Hint
Refer to key_moments about session creation.
Concept Snapshot
Snowpark for Python basics:
- Create a Session to connect to Snowflake
- Load data as a DataFrame from a table
- Use DataFrame methods like filter() to transform data
- Use show() to display results
- Session manages connection lifecycle
Full Transcript
This lesson shows how to use Snowpark for Python to work with data in Snowflake. First, you create a session object that connects your Python code to Snowflake. Then you load a table into a DataFrame. You can transform the data by filtering rows, for example selecting only rows where AGE is greater than 30. Finally, you use the show() method to print the filtered data to the console. The session object remains active until you close it or end your program. This step-by-step process helps beginners see how Snowpark manages data access and transformation in a simple way.