Created
September 23, 2019 22:14
-
-
Save oneryalcin/d9f6921311611fcc07764d86c0269b72 to your computer and use it in GitHub Desktop.
6 Sparkify Session Count and Avg Song Count/Session
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
user_engagement = data\ | |
.groupBy('userId', 'sessionId')\ | |
.agg(F.max('itemInSession').alias('itemCount'))\ | |
.groupBy('userId')\ | |
.agg({"itemCount": "mean", "sessionId": "count"})\ | |
.withColumnRenamed('count(sessionId)', 'sessionCount')\ | |
.withColumnRenamed('avg(itemCount)', 'meanSongCount')\ | |
.orderBy('userId') | |
user_engagement.show(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment