Skip to content

Instantly share code, notes, and snippets.

@drorata
Forked from dr-dror/demo.ipynb
Created November 17, 2024 07:34
Show Gist options
  • Save drorata/f6652f326b828e6def914a04ea532be8 to your computer and use it in GitHub Desktop.
Save drorata/f6652f326b828e6def914a04ea532be8 to your computer and use it in GitHub Desktop.
Pivot a dataframe directly using Spark SQL
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
SELECT
*
FROM
(
SELECT
date_format (tpep_pickup_datetime, 'EEEE') AS day_of_week,
fare_amount,
passenger_count
FROM
data
) PIVOT (
{agg_func}(fare_amount) FOR day_of_week IN (
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
)
)
ORDER BY
passenger_count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment