Created
September 27, 2024 15:06
-
-
Save dr-dror/0f59e31e4d7d7dbd8d191ba816bd67dd to your computer and use it in GitHub Desktop.
Pivot a dataframe directly using Spark SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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