0
0
Snowflakecloud~10 mins

DataFrame API in Snowpark in Snowflake - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Snowpark DataFrame from a table named 'employees'.

Snowflake
df = session.table([1])
Drag options to blanks, or click blank then click option'
Aemployees
B"employees"
C'employees'
Dtable_employees
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the table name
Using a variable name instead of a string
2fill in blank
medium

Complete the code to select the 'name' and 'salary' columns from the DataFrame.

Snowflake
df_selected = df.select([1])
Drag options to blanks, or click blank then click option'
A"name", "salary"
B"name", salary
Dname, salary
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting column names
Using variables instead of strings
3fill in blank
hard

Fix the error in the code to filter rows where salary is greater than 50000.

Snowflake
df_filtered = df.filter(df[[1]] > 50000)
Drag options to blanks, or click blank then click option'
A"salary"
Bsalary
C'salary'
Ddf.salary
Attempts:
3 left
💡 Hint
Common Mistakes
Using the column name without quotes inside brackets
Using dot notation inside brackets
4fill in blank
hard

Fill both blanks to create a new column 'bonus' which is 10% of 'salary' and select it along with 'name'.

Snowflake
df_new = df.select([1], (df[[2]] * 0.1).alias("bonus"))
Drag options to blanks, or click blank then click option'
A"name"
B"salary"
Csalary
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted column names inside brackets
Mixing quoted and unquoted column names
5fill in blank
hard

Fill all three blanks to group by 'department', calculate average 'salary' as 'avg_salary', and filter departments with avg_salary > 60000.

Snowflake
df_grouped = df.groupBy([1]).agg(df[[2]].avg().alias([3])).filter("avg_salary > 60000")
Drag options to blanks, or click blank then click option'
A"department"
B"salary"
C"avg_salary"
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting column names
Using unquoted alias names