Menu
CoddyTech

Recap: Stock Report

Part of the Fundamentals section of Coddy's PySpark journey. Lesson 9 of 18.

challenge icon

Challenge

Easy

Replace missing stock with zero. Keep rows with stock greater than zero. Add value = price * stock, then return item, value sorted by item ascending. Item names are unique; prices are non-null.

Write transform(df) and return a Spark DataFrame. The checker supplies df with schema item string, price int, stock int. The session and F (PySpark functions) are already available. Do not print; the checker displays the returned rows. Return columns in this order: item, value.

Try it yourself

def transform(df):
    return df

All lessons in Fundamentals

Practice on your own: Online Python compiler