The file datasets/csv/users.csv holds one row per customer. Read it with Spark and
return the customers from India who are 30 or older.
paths['users'].country == 'India' and age >= 30.age descending, then by user_id ascending.user_id, first_name, last_name, country, age.File questions receive the path as a third argument:
from pyspark.sql import functions as F
def solve(spark, dfs, paths):
users = spark.read.csv(paths['users'], header=True, inferSchema=True)
return (users
.filter((F.col('country') == 'India') & (F.col('age') >= 30))
.select('user_id', 'first_name', 'last_name', 'country', 'age')
.orderBy(F.col('age').desc(), F.col('user_id')))
The same data is also preloaded as dfs['users'] 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.
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'].
users]Column names and order must match. Sort order is specified in the question.