Skip to content

Commit d040501

Browse files
author
bitoollearner
committed
LeetCode Pyspark Solution
1 parent 7d4966e commit d040501

10 files changed

+1980
-70
lines changed

Solved/2669. Count Artist Occurrences On Spotify Ranking List (Easy)-(Solved).ipynb

Lines changed: 137 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"cell_type": "markdown",
55
"metadata": {
66
"application/vnd.databricks.v1+cell": {
7-
"cellMetadata": {},
7+
"cellMetadata": {
8+
"byteLimit": 2048000,
9+
"rowLimit": 10000
10+
},
811
"inputWidgets": {},
912
"nuid": "4e9d71b1-88e9-445c-820a-b842e217a4e7",
1013
"showTitle": false,
@@ -21,7 +24,10 @@
2124
"execution_count": 0,
2225
"metadata": {
2326
"application/vnd.databricks.v1+cell": {
24-
"cellMetadata": {},
27+
"cellMetadata": {
28+
"byteLimit": 2048000,
29+
"rowLimit": 10000
30+
},
2531
"inputWidgets": {},
2632
"nuid": "e6624c4d-8cb8-4ac4-8c72-81d1b4ecdb57",
2733
"showTitle": false,
@@ -40,7 +46,10 @@
4046
"cell_type": "markdown",
4147
"metadata": {
4248
"application/vnd.databricks.v1+cell": {
43-
"cellMetadata": {},
49+
"cellMetadata": {
50+
"byteLimit": 2048000,
51+
"rowLimit": 10000
52+
},
4453
"inputWidgets": {},
4554
"nuid": "c3788fe5-f4c9-420f-ad72-ec1a39310a2a",
4655
"showTitle": false,
@@ -97,15 +106,27 @@
97106
"execution_count": 0,
98107
"metadata": {
99108
"application/vnd.databricks.v1+cell": {
100-
"cellMetadata": {},
109+
"cellMetadata": {
110+
"byteLimit": 2048000,
111+
"rowLimit": 10000
112+
},
101113
"inputWidgets": {},
102114
"nuid": "137536ea-9bec-4171-8dc2-4bf8b0d771b4",
103115
"showTitle": false,
104116
"tableResultSettingsMap": {},
105117
"title": ""
106118
}
107119
},
108-
"outputs": [],
120+
"outputs": [
121+
{
122+
"output_type": "stream",
123+
"name": "stdout",
124+
"output_type": "stream",
125+
"text": [
126+
"+-------+------------------+----------+\n| id| track_name| artist|\n+-------+------------------+----------+\n| 303651|Heart Won't Forget| Sia|\n|1046089| Shape of you|Ed Sheeran|\n| 33445| I'm the one| DJ Khalid|\n| 811266|Young Dumb & Broke| DJ Khalid|\n| 505727| Happier|Ed Sheeran|\n+-------+------------------+----------+\n\n"
127+
]
128+
}
129+
],
109130
"source": [
110131
"spotify_data_2669 = [\n",
111132
" (303651, \"Heart Won't Forget\", \"Sia\"),\n",
@@ -119,15 +140,124 @@
119140
"spotify_df_2669 = spark.createDataFrame(spotify_data_2669, spotify_columns_2669)\n",
120141
"spotify_df_2669.show()"
121142
]
143+
},
144+
{
145+
"cell_type": "code",
146+
"execution_count": 0,
147+
"metadata": {
148+
"application/vnd.databricks.v1+cell": {
149+
"cellMetadata": {
150+
"byteLimit": 2048000,
151+
"rowLimit": 10000
152+
},
153+
"inputWidgets": {},
154+
"nuid": "d8cfc9be-e847-4e0a-9fd5-7652d74bde8f",
155+
"showTitle": false,
156+
"tableResultSettingsMap": {},
157+
"title": ""
158+
}
159+
},
160+
"outputs": [
161+
{
162+
"output_type": "display_data",
163+
"data": {
164+
"text/html": [
165+
"<style scoped>\n",
166+
" .table-result-container {\n",
167+
" max-height: 300px;\n",
168+
" overflow: auto;\n",
169+
" }\n",
170+
" table, th, td {\n",
171+
" border: 1px solid black;\n",
172+
" border-collapse: collapse;\n",
173+
" }\n",
174+
" th, td {\n",
175+
" padding: 5px;\n",
176+
" }\n",
177+
" th {\n",
178+
" text-align: left;\n",
179+
" }\n",
180+
"</style><div class='table-result-container'><table class='table-result'><thead style='background-color: white'><tr><th>artist</th><th>occurrences</th></tr></thead><tbody><tr><td>DJ Khalid</td><td>2</td></tr><tr><td>Ed Sheeran</td><td>2</td></tr><tr><td>Sia</td><td>1</td></tr></tbody></table></div>"
181+
]
182+
},
183+
"metadata": {
184+
"application/vnd.databricks.v1+output": {
185+
"addedWidgets": {},
186+
"aggData": [],
187+
"aggError": "",
188+
"aggOverflow": false,
189+
"aggSchema": [],
190+
"aggSeriesLimitReached": false,
191+
"aggType": "",
192+
"arguments": {},
193+
"columnCustomDisplayInfos": {},
194+
"data": [
195+
[
196+
"DJ Khalid",
197+
2
198+
],
199+
[
200+
"Ed Sheeran",
201+
2
202+
],
203+
[
204+
"Sia",
205+
1
206+
]
207+
],
208+
"datasetInfos": [],
209+
"dbfsResultPath": null,
210+
"isJsonSchema": true,
211+
"metadata": {},
212+
"overflow": false,
213+
"plotOptions": {
214+
"customPlotOptions": {},
215+
"displayType": "table",
216+
"pivotAggregation": null,
217+
"pivotColumns": null,
218+
"xColumns": null,
219+
"yColumns": null
220+
},
221+
"removedWidgets": [],
222+
"schema": [
223+
{
224+
"metadata": "{}",
225+
"name": "artist",
226+
"type": "\"string\""
227+
},
228+
{
229+
"metadata": "{}",
230+
"name": "occurrences",
231+
"type": "\"long\""
232+
}
233+
],
234+
"type": "table"
235+
}
236+
},
237+
"output_type": "display_data"
238+
}
239+
],
240+
"source": [
241+
"spotify_df_2669\\\n",
242+
" .groupBy(\"artist\")\\\n",
243+
" .agg(count(\"*\").alias(\"occurrences\"))\\\n",
244+
" .orderBy(col(\"occurrences\").desc(), col(\"artist\").asc()).display()"
245+
]
122246
}
123247
],
124248
"metadata": {
125249
"application/vnd.databricks.v1+notebook": {
126-
"computePreferences": null,
250+
"computePreferences": {
251+
"hardware": {
252+
"accelerator": null,
253+
"gpuPoolId": null,
254+
"memory": null
255+
}
256+
},
127257
"dashboards": [],
128258
"environmentMetadata": {
129259
"base_environment": "",
130-
"environment_version": "1"
260+
"environment_version": "2"
131261
},
132262
"inputWidgetPreferences": null,
133263
"language": "python",

0 commit comments

Comments
 (0)