← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Pandas coding question for a Data Scientist role at Google. One problem, fairly involved, with a lot of edge cases baked in around NaN handling and operator precedence. Felt like a take-home but was probably a live technical screen.

Questions Asked (1)

Q1

Using pandas, add a new column 'risk_tier' to a DataFrame based on a strict hierarchy of conditions: 'high' if returns >= 2 OR last_review_rating <= 2.0, 'medium' if amount >= 200 AND country is US or CA, 'new' if signup_date falls within 30 days before 2025-09-01, and 'low' otherwise. Must be fully vectorized, handle NaNs in last_review_rating without incorrectly triggering 'high', and include a basic unit test.

Algorithms & Data StructuresTechnical Trade-offsData Modeling
Author's notes

The NaN condition is the thing that gets you.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the hierarchy and edge cases, especially NaN handling in last_review_rating. Then implement a fully vectorized solution using numpy.select or boolean masks with proper NaN-safe comparisons, and finally write a unit test covering all tiers and NaN cases.

Pro tip: Use numpy.select with a default value to enforce the hierarchy cleanly, and explicitly handle NaN by filling or using a mask that excludes NaN from the 'high' condition. This avoids silent bugs and demonstrates production-ready thinking.

1. Clarify requirements and edge cases

Confirm the strict order of conditions, how to treat NaN in last_review_rating, and whether signup_date is inclusive. This ensures alignment before coding.

2. Design a vectorized solution

Use numpy.select or boolean masks to apply conditions in order, ensuring NaN-safe comparisons (e.g., fillna or use pd.notna). Avoid apply or loops.

3. Implement the logic

Write the code: create boolean masks for each condition, combine with & and |, and assign 'risk_tier' using np.select with default 'low'.

4. Write a unit test

Create a small DataFrame with cases for each tier, including NaN in last_review_rating, and assert the resulting risk_tier column matches expectations.

5. Review and optimize

Check for performance (e.g., avoid repeated computations) and readability. Discuss trade-offs like using np.select vs. multiple loc assignments.

Key Points to Mention

  • Vectorization with numpy.select or boolean masks for performance and clarity.
  • NaN handling: use pd.notna or fillna to prevent NaN from incorrectly triggering 'high'.
  • Strict hierarchy: conditions must be evaluated in order, with 'low' as default.
  • Date condition: signup_date within 30 days before 2025-09-01 (i.e., >= 2025-08-02 and < 2025-09-01).
  • Unit test: include edge cases like NaN, boundary dates, and each tier.
  • Trade-offs: np.select vs. apply vs. multiple loc assignments; readability vs. performance.

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