Skip to content

32. New Users per Day

Difficulty: Medium · Topics: Aggregations

From the events log (many events per user per day), count how many users were seen for the first time on each day.

Return day and new_users, only for days with at least one new user.

Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.

Sample data

events

user_idday
12024-01-01
22024-01-01
12024-01-02
32024-01-02
12024-01-01

Expected output

daynew_users
2024-01-012
2024-01-021

Hints

Hint 1First find each user's first day: groupBy("user_id").agg(F.min("day")).
Hint 2Then count users per first day.
Hint 3Days on which only returning users appear simply don't show up.

PySpark functions you'll practise

Related problems

Browse

Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings

Difficulty: Easy · Medium · Hard · PySpark interview roadmap · All problems