Analyze Document Collaboration CSVs
NotionData Scientist · Technical ScreenLast updated
This problem tests your ability to clean, join, and analyze messy user-activity data using pandas or SQL, focusing on window functions and handling missing values.
Scenario
You are analyzing user collaboration data for a document editor. You have two datasets:
edits.csv: Records of every document edit (user_id,doc_id,timestamp,edit_size_bytes).documents.csv: Metadata for documents (doc_id,owner_id,created_at,is_private).
Some user_id fields are null (indicating anonymous guests). You need to calculate the "Daily Active Contributor" (DAC) rate: the percentage of documents that had at least one edit from an owner vs. an anonymous guest on a given day.
Task
Write a function or query that returns a table with the following columns: date, percent_owner_edits, and percent_guest_edits.
Constraints
timestampis in ISO format.- Ignore edits to documents where
is_privateis true. - Handle potential duplicate timestamps if multiple edits occurred in the same second.
Example
Input edits:
| user_id | doc_id | timestamp | edit_size_bytes |
|---|---|---|---|
| 101 | A | 2023-01-01 | 50 |
| NULL | A | 2023-01-01 | 20 |
Input documents:
| doc_id | owner_id | is_private |
|---|---|---|
| A | 101 | False |
Output:
| date | percent_owner_edits | percent_guest_edits |
|---|---|---|
| 2023-01-01 | 100.0 | 100.0 |
Note: If a doc has both owner and guest edits, both metrics count it for that day.
Hints
Hint 1
First, filter out private documents and cast timestamps to a date-only format.
Hint 2
Perform a left join between your cleaned edits table and the documents table to associate every edit with an owner_id.
Hint 3
Use a group-by on date and document, then compare the edit's user_id against the document's owner_id to create boolean flags for 'is_owner_edit' and 'is_guest_edit'.
Follow-up questions
- How would you handle documents that have zero edits on a specific day to avoid 'gaps' in your time-series report?
- If the edit volume grows to billions of rows, how would you optimize this calculation for a production environment?
- How would you determine if an anonymous user is actually a logged-out returning user based on IP or cookie identifiers?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.