59. Pivot with Several Aggregations
Difficulty: Hard · Topics: Pivot, Unpivot & Rollup, Aggregations, Null Handling
An advanced problem: unlock it to open the statement, sample data and editor. Graded on 3 test cases.
Learn the concepts
- fillna / dropna · 4 min read. Fill or drop missing values per column, and why fillna(0) leaves string columns alone.
- pivot · 5 min read. Turn row values into columns, and why passing the values list up front makes it faster.
- groupBy + agg · 4 min read. Aggregate rows per group: counts, sums, averages, and how count(*) differs from count(col).
PySpark functions you'll practise
- groupBy
- agg
- sum
- count
- pivot
- fillna
Related problems
- All Combinations with CUBE · Hard · Pivot, Unpivot & Rollup, Aggregations, Conditional Logic
- Subtotals with ROLLUP · Hard · Pivot, Unpivot & Rollup, Aggregations, Conditional Logic, Filtering & Selection
- Pivot Quarterly Revenue · Medium · Pivot, Unpivot & Rollup, Aggregations
- Survey Scores by Question · Medium · Pivot, Unpivot & Rollup, Aggregations
- Unpivot Wide Columns to Rows · Medium · Pivot, Unpivot & Rollup, Null Handling, Filtering & Selection
Browse
Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings · Data Lake · Lakehouse · Streaming · Data Prep for AI · Spark Performance
Difficulty: Easy · Medium · Hard · Learn · All problems · dbt practice