Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Conditional Aggregation

PySpark data engineering interview problem. Difficulty: intermediate. Pattern: Aggregation. About 16 minutes. Part of the Pro drill bank.

Electronics and Clothing revenue in one aggregate row. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

From df, return one row with electronics_revenue and clothing_revenue as conditional sums over those categories. Assign result.

Constraints

  • One output row.
  • Ignore other categories.

Examples

Input: category amounts Output: electronics_revenue | clothing_revenue 220.0 | 70.0 Food is ignored by both conditional sums.

Topics: lakebench, pyspark, when, sum.

More PySpark interview questions · All interview problems · Learn data engineering

intermediate

Conditional Aggregation

Interview-style drill: Electronics and Clothing revenue in one aggregate row.

From `df`, return one row with `electronics_revenue` and `clothing_revenue` as conditional sums over those categories. Assign `result`.