Final: Regional Revenue
Part of the Fundamentals section of Coddy's PySpark journey. Lesson 18 of 18.
Challenge
EasyBuild a regional revenue report. Replace missing quantity with zero. Exclude rows with quantity less than or equal to zero, or price less than zero. Compute revenue = price * quantity. Sum revenue for each region. Return region, revenue ordered by revenue descending, then region ascending. Regions and prices are non-null.
Write transform(df) and return a Spark DataFrame. The checker supplies df with schema region string, price int, quantity int. The session and F (PySpark functions) are already available. Do not print; the checker displays the returned rows. Return columns in this order: region, revenue.
Try it yourself
def transform(df):
return df
All lessons in Fundamentals
Practice on your own: Online Python compiler