Read CSV Out of Stock Products

Easy
File I/O
CSV
Filtering

Read CSV Out of Stock Products

The file datasets/csv/products.csv holds one row per product. Find the products that are out of stock - their stock_quantity is 0.

What to do

  1. Read the CSV file from disk. Its local path is handed to you as paths['products'].
  2. Keep the rows where stock_quantity == 0.
  3. Return exactly these columns: product_id, product_name, category, price.
  4. Sort by product_id ascending.

Signature

File questions receive the path as a third argument:

from pyspark.sql import functions as F

def solve(spark, dfs, paths):
    products = spark.read.csv(paths['products'], header=True, inferSchema=True)
    # TODO: filter, select and sort
    return products

The same data is also preloaded as dfs['products'] if you prefer to skip the file read.

This question runs in your browser - no sign-in needed. Press Run for the sample data and Submit for the hidden data.

Browser Engine: Evaluates PySpark DataFrame & SQL logic locally in Pyodide WebAssembly.

Input files

1 File
Loaded automatically

These files are loaded into this browser when you run. Their paths are handed to your code as the third argument: solve(spark, dfs, paths). Read one with spark.read.csv(paths['users'], header=True), or skip the read and use dfs['users'].

paths[products]
csv
180 rows
datasets/csv/products.csv
product_id(int)
product_name(string)
category(string)
sub_category(string)
brand(string)
price(double)
stock_quantity(int)
created_at(timestamp)

Return these columns

product_id(int)
product_name(string)
category(string)
price(double)

Column names and order must match. Sort order is specified in the question.

Browser engine
Local files
Loading Python editor…
Click Run to try the sample cases, or Submit to check the hidden cases. First run caches the browser Python engine (~8–15s once); all code stays on your device.