← DoorDash Interview Insights

DoorDash·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Apr 2024Remote

Summary

DoorDash data scientist interview focused on a clickstream pipeline scenario. The technical portion mixed Pandas wrangling with SQL, which felt reasonable until the lambda-based tiering question made me second-guess my groupby instincts.

Questions Asked (2)

Q1

Using Pandas, aggregate total revenue and distinct purchase counts per user from an events table, then use a lambda inside apply to classify each user into a revenue tier (zero, low, high).

Product Analytics & MetricsAlgorithms & Data Structures
Author's notes

The groupby part was fine but I fumbled the lambda for a second because I kept second-guessing whether to apply it on the grouped object or after resetting the index.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions (e.g., revenue column, purchase event, distinct purchase count). Then use groupby.agg with named aggregation to compute total revenue and nunique of purchase IDs per user, and finally apply a lambda with a tiering function (e.g., if-elif-else) to classify each user into zero, low, or high revenue tiers.

Pro tip: Mention that for large datasets, you can avoid apply by using pd.cut or np.select for better performance, but since the question asks for lambda inside apply, demonstrate that while noting the trade-off. Also, define tier thresholds explicitly and handle edge cases like zero revenue and missing values.

1. Clarify requirements and data schema

Ask about the events table columns (e.g., user_id, revenue, purchase_id, event_type) and confirm that 'distinct purchase counts' means counting unique purchase events per user. Define revenue tiers (e.g., zero: revenue == 0, low: 0 < revenue <= threshold, high: revenue > threshold).

2. Aggregate per user

Use df.groupby('user_id').agg(total_revenue=('revenue', 'sum'), distinct_purchases=('purchase_id', 'nunique')) to compute total revenue and distinct purchase counts. Ensure to handle potential NaN values appropriately.

3. Define tiering logic

Write a function or lambda that takes a revenue value and returns 'zero', 'low', or 'high' based on predefined thresholds. For example: lambda x: 'zero' if x == 0 else ('low' if x <= 100 else 'high').

4. Apply lambda to classify users

Use .apply() on the total_revenue column to create a new 'revenue_tier' column: df['revenue_tier'] = df['total_revenue'].apply(lambda x: ...). Alternatively, use .assign() for a cleaner pipeline.

5. Validate and present results

Check the distribution of tiers, ensure no unexpected values, and display the final DataFrame with user_id, total_revenue, distinct_purchases, and revenue_tier. Mention potential optimizations like vectorized operations.

Key Points to Mention

  • Use of groupby with named aggregation for clarity and efficiency.
  • nunique for distinct purchase counts, ensuring only unique purchases are counted.
  • Lambda function inside apply for tier classification, with clear threshold definitions.
  • Handling edge cases: zero revenue, negative revenue (if applicable), and missing values.
  • Performance consideration: apply with lambda can be slow for large data; mention alternatives like pd.cut or np.select.
  • Business context: revenue tiers help segment users for targeted marketing or analysis.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Write a SQL query that returns, for each platform, the daily conversion rate defined as purchases divided by clicks over the last 30 days.

Product Analytics & MetricsData Modeling
Author's notes

Classic conditional aggregation.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions (e.g., tables for clicks and purchases, platform column, date range). Then write a query that aggregates clicks and purchases per platform per day, filters to the last 30 days, and computes the ratio. Use a LEFT JOIN or UNION ALL to combine events, ensuring all platforms and dates are covered.

Pro tip: Mention that you would validate the conversion rate by checking for outliers or missing data, and consider using a window function to handle days with zero clicks to avoid division by zero errors.

1. Clarify requirements and schema

Ask about table structures, column names, and definitions (e.g., what constitutes a click or purchase, time zone). Confirm the date range and whether 'last 30 days' includes today.

2. Aggregate events per platform per day

Write subqueries or CTEs to count clicks and purchases separately, grouped by platform and date. Ensure you filter to the last 30 days in each subquery.

3. Combine aggregates and compute conversion rate

Join the click and purchase aggregates on platform and date, using a LEFT JOIN to keep all platform-date combinations. Compute conversion rate as purchases divided by clicks, handling division by zero.

4. Handle edge cases and validate

Use COALESCE or NULLIF to avoid division by zero. Consider if days with zero clicks should be included (rate = 0 or NULL). Validate results by checking for anomalies.

Key Points to Mention

  • Use of CTEs or subqueries for readability and modularity
  • Filtering for the last 30 days using date functions (e.g., DATE_SUB, CURRENT_DATE)
  • Handling division by zero with NULLIF or CASE statements
  • Using LEFT JOIN to ensure all platforms and dates are represented
  • Considering time zone and date truncation (e.g., daily granularity)
  • Potential need to aggregate across multiple event tables or use UNION ALL

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.