generated from mine-cetinkaya-rundel/olympicdash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholympicdash-py-3.quarto_ipynb
663 lines (663 loc) · 23.3 KB
/
olympicdash-py-3.quarto_ipynb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"title: \"Olympic Games\"\n",
"format: \n",
" dashboard:\n",
" orientation: columns\n",
" nav-buttons: [github]\n",
" github: https://github.com/posit-conf-2024/olympicdash\n",
"logo: images/olympics-logo.svg\n",
"logo-alt: \"Olympics logo with multicolored circles.\"\n",
"---"
],
"id": "637b2dd1"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: load-packages\n",
"from plotnine import *\n",
"import great_tables as gt\n",
"import pandas as pd"
],
"id": "load-packages",
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: load-data\n",
"olympics_full = pd.read_csv(\"data/olympics.csv\", low_memory = False)"
],
"id": "load-data",
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: prep-data\n",
"# Filter for non-NA medals\n",
"olympics = olympics_full[(olympics_full[\"medal\"].notna())]\n",
"\n",
"# Split the team column at \"-\" into two columns\n",
"split_data = olympics[\"team\"].str.split(\"-\", n = 1, expand = True)\n",
"olympics.loc[:, \"team\"] = split_data[0]\n",
"\n",
"# Reorder the medal column categories\n",
"olympics[\"medal\"] = pd.Categorical(olympics[\"medal\"], categories = [\"Bronze\", \"Silver\", \"Gold\"])"
],
"id": "prep-data",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 🌞 Summer Olympics\n"
],
"id": "188e024e"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: summmer-prep-data\n",
"summer_olympics = olympics[(olympics[\"season\"] == \"Summer\")]\n",
"summer_olympics.reset_index(drop=True, inplace=True)"
],
"id": "summmer-prep-data",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Column - Medals by sport and year {width=\"65%\"}\n",
"\n",
"### Row - Medals by sport {height=\"60%\"}\n"
],
"id": "2148a528"
},
{
"cell_type": "code",
"metadata": {
"title": "Medals by sport"
},
"source": [
"#| label: summer-medals-by-sport\n",
"\n",
"# Lump the sport column to top 15 categories, grouping others as Other\n",
"top_15_sports = summer_olympics[\"sport\"].value_counts().nlargest(15).index\n",
"summer_olympics[\"sport\"] = summer_olympics[\"sport\"].apply(lambda x: x if x in top_15_sports else \"Other\")\n",
"\n",
"# Convert the sport column to a categorical type with order based on frequency, and reverse the order\n",
"summer_olympics[\"sport\"] = pd.Categorical(summer_olympics[\"sport\"], categories = summer_olympics[\"sport\"].value_counts().index[::-1])\n",
"\n",
"# Move the Other category of the sport column to the beginning\n",
"new_order = [\"Other\"] + [cat for cat in summer_olympics[\"sport\"].cat.categories if cat != \"Other\"]\n",
"summer_olympics[\"sport\"] = summer_olympics[\"sport\"].cat.reorder_categories(new_order)\n",
"\n",
"# Plot\n",
"(\n",
" ggplot(summer_olympics, aes(x = \"sport\", fill = \"medal\")) +\n",
" geom_bar() +\n",
" coord_flip() +\n",
" guides(fill = guide_legend(reverse = True)) +\n",
" labs(\n",
" x = \"\",\n",
" y = \"\",\n",
" fill = \"Medal\"\n",
" ) +\n",
" theme_minimal() +\n",
" theme(\n",
" legend_position = \"inside\",\n",
" legend_position_inside = (0.9, 0.2),\n",
" legend_direction = \"horizontal\",\n",
" legend_background = element_rect(fill = \"white\", color = \"gray\"),\n",
" figure_size = (10, 6.18)\n",
" )\n",
")"
],
"id": "summer-medals-by-sport",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Row - Medals by year {height=\"40%\"}\n",
"\n",
"::: {.card title=\"Medals by year\"}\n",
"Due to World War II, no olympic games were held in 1940 and 1944.\n"
],
"id": "499e7689"
},
{
"cell_type": "code",
"metadata": {
"title": "Medals by year"
},
"source": [
"#| label: summer-medals-by-year\n",
"\n",
"# Count the occurrences of each medal per year\n",
"summer_olympics_count = summer_olympics.groupby([\"year\", \"medal\"], observed=True).size().reset_index(name = \"n\")\n",
"\n",
"# Plot\n",
"(\n",
" ggplot(summer_olympics_count, aes(x = \"year\", y = \"n\", color = \"medal\")) +\n",
" geom_point(size = 0.5) +\n",
" geom_line() +\n",
" guides(color = guide_legend(reverse = True)) + \n",
" scale_x_continuous(breaks = range(1896, 2020, 8)) +\n",
" labs(x = \"Year\", y = \"\", color = \"Medal\") +\n",
" theme_minimal() +\n",
" theme(\n",
" legend_position = \"inside\",\n",
" legend_position_inside = (0.9, 0.2),\n",
" legend_direction = \"horizontal\",\n",
" legend_background = element_rect(fill = \"white\", color = \"gray\"),\n",
" figure_size = (10, 3)\n",
" )\n",
")"
],
"id": "summer-medals-by-year",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
":::\n",
"\n",
"## Column - Medals by country {width=\"35%\"}\n",
"\n",
"### Row - Value boxes {height=\"30%\"}\n"
],
"id": "acea70ba"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: summer-calculate-most-medals\n",
"\n",
"# Filter for gold medals\n",
"gold_medals = summer_olympics[summer_olympics['medal'] == 'Gold']\n",
"# Group by team and count gold medals\n",
"gold_medal_counts = gold_medals.groupby('team').size()\n",
"# Find the team with the most gold medals\n",
"most_gold_medals = gold_medal_counts.idxmax()\n",
"count_most_gold_medals = gold_medal_counts.max()\n",
"\n",
"# Filter for silver medals\n",
"silver_medals = summer_olympics[summer_olympics['medal'] == 'Silver']\n",
"# Group by team and count silver medals\n",
"silver_medal_counts = silver_medals.groupby('team').size()\n",
"# Find the team with the most silver medals\n",
"most_silver_medals = silver_medal_counts.idxmax()\n",
"count_most_silver_medals = silver_medal_counts.max()\n",
"\n",
"# Filter for bronze medals\n",
"bronze_medals = summer_olympics[summer_olympics['medal'] == 'Bronze']\n",
"# Group by team and count bronze medals\n",
"bronze_medal_counts = bronze_medals.groupby('team').size()\n",
"# Find the team with the most bronze medals\n",
"most_bronze_medals = bronze_medal_counts.idxmax()\n",
"count_most_bronze_medals = bronze_medal_counts.max()"
],
"id": "summer-calculate-most-medals",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"::: {.valuebox icon=\"award-fill\" color=\"#d4af37\"}\n",
"Most golds:\n",
"\n",
"`{python} str(count_most_gold_medals)`\n",
"\n",
"`{python} most_gold_medals`\n",
":::\n",
"\n",
"::: {.valuebox icon=\"award-fill\" color=\"#c0c0c0\"}\n",
"Most silvers:\n",
"\n",
"`{python} str(count_most_silver_medals)`\n",
"\n",
"`{python} most_silver_medals`\n",
":::\n",
"\n",
"::: {.valuebox icon=\"award-fill\" color=\"#cd7f32\"}\n",
"Most bronzes:\n",
"\n",
"`{python} str(count_most_bronze_medals)`\n",
"\n",
"`{python} most_bronze_medals`\n",
":::\n",
"\n",
"### Row - Tabsets of tables {.tabset height=\"70%\"}\n"
],
"id": "e8f40524"
},
{
"cell_type": "code",
"metadata": {
"title": "Medals by country"
},
"source": [
"#| label: summer-medals-by-country\n",
"\n",
"# Count the occurrences of each medal per team\n",
"summer_olympics_count = summer_olympics.groupby([\"team\", \"medal\"]).size().reset_index(name=\"n\")\n",
"\n",
"# Pivot olympics_count to get medals as columns\n",
"summer_olympics_pivot = summer_olympics_count.pivot_table(index = \"team\", columns = \"medal\", values = \"n\", fill_value = 0)\n",
"\n",
"# Calculate the total number of medals\n",
"summer_olympics_pivot[\"Total\"] = summer_olympics_pivot[[\"Bronze\", \"Gold\", \"Silver\"]].sum(axis=1)\n",
"\n",
"# Reset the index and rearrange columns\n",
"summer_olympics_pivot = summer_olympics_pivot.reset_index()\n",
"summer_olympics_pivot = summer_olympics_pivot[[\"team\", \"Gold\", \"Silver\", \"Bronze\", \"Total\"]]\n",
"\n",
"# Sort by Total medals, then team\n",
"summer_olympics_sorted_descending = summer_olympics_pivot.sort_values(by=[\"Total\", \"team\"], ascending=[False, True])\n",
"summer_olympics_sorted_ascending = summer_olympics_pivot.sort_values(by=[\"Total\", \"team\"], ascending=[True, True])\n",
"\n",
"# Remove Total\n",
"summer_olympics_sorted_descending = summer_olympics_sorted_descending[[\"team\", \"Gold\", \"Silver\", \"Bronze\"]]\n",
"summer_olympics_sorted_ascending = summer_olympics_sorted_ascending[[\"team\", \"Gold\", \"Silver\", \"Bronze\"]]\n",
"\n",
"# Rename the team column to Team\n",
"summer_olympics_sorted_descending.rename(columns={\"team\": \"Team\"}, inplace=True)\n",
"summer_olympics_sorted_ascending.rename(columns={\"team\": \"Team\"}, inplace=True)\n",
"\n",
"# Find top and bottom 30\n",
"summer_olympics_sorted_descending_top30 = summer_olympics_sorted_descending.head(30)\n",
"summer_olympics_sorted_descending_top30.reset_index(drop=True, inplace=True)\n",
"summer_olympics_sorted_ascending_bottom30 = summer_olympics_sorted_ascending.head(30)\n",
"summer_olympics_sorted_ascending_bottom30.reset_index(drop=True, inplace=True)"
],
"id": "summer-medals-by-country",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"::: {.card title=\"Top 30 total medals\"}\n",
"Teams sorted in descending order of total medals.\n"
],
"id": "bfc81647"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: summer-top-30-medals\n",
"(\n",
" gt.GT(summer_olympics_sorted_descending_top30).data_color(\n",
" columns=[\"Gold\", \"Silver\", \"Bronze\"],\n",
" palette=\"Oranges\"\n",
" )\n",
")"
],
"id": "summer-top-30-medals",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
":::\n",
"\n",
"::: {.card title=\"Bottom 30 total medals\"}\n",
"Teams sorted in ascending order of total medals.\n"
],
"id": "4f191564"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: summer-bottom-30-medals\n",
"(\n",
" gt.GT(summer_olympics_sorted_ascending_bottom30).data_color(\n",
" columns=[\"Gold\", \"Silver\", \"Bronze\"],\n",
" palette=\"Blues\"\n",
" )\n",
")"
],
"id": "summer-bottom-30-medals",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
":::\n",
"\n",
"# ❄️ Winter Olympics\n"
],
"id": "30e894fe"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: winter-prep-data\n",
"winter_olympics = olympics[(olympics[\"season\"] == \"Winter\")]\n",
"winter_olympics.reset_index(drop=True, inplace=True)"
],
"id": "winter-prep-data",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Column - Medals by sport and year {width=\"65%\"}\n",
"\n",
"### Row - Medals by sport {height=\"60%\"}\n"
],
"id": "5a27154e"
},
{
"cell_type": "code",
"metadata": {
"title": "Medals by sport"
},
"source": [
"#| label: winter-medals-by-sport\n",
"\n",
"# Lump the sport column to top 15 categories, grouping others as Other\n",
"top_15_sports = winter_olympics[\"sport\"].value_counts().nlargest(15).index\n",
"winter_olympics[\"sport\"] = winter_olympics[\"sport\"].apply(lambda x: x if x in top_15_sports else \"Other\")\n",
"\n",
"# Convert the sport column to a categorical type with order based on frequency, and reverse the order\n",
"winter_olympics[\"sport\"] = pd.Categorical(winter_olympics[\"sport\"], categories = winter_olympics[\"sport\"].value_counts().index[::-1])\n",
"\n",
"# Move the Other category of the sport column to the beginning\n",
"new_order = [\"Other\"] + [cat for cat in winter_olympics[\"sport\"].cat.categories if cat != \"Other\"]\n",
"winter_olympics[\"sport\"] = winter_olympics[\"sport\"].cat.reorder_categories(new_order)\n",
"\n",
"# Plot\n",
"(\n",
" ggplot(winter_olympics, aes(x = \"sport\", fill = \"medal\")) +\n",
" geom_bar() +\n",
" coord_flip() +\n",
" guides(fill = guide_legend(reverse = True)) +\n",
" labs(\n",
" x = \"\",\n",
" y = \"\",\n",
" fill = \"Medal\"\n",
" ) +\n",
" theme_minimal() +\n",
" theme(\n",
" legend_position = \"inside\",\n",
" legend_position_inside = (0.9, 0.2),\n",
" legend_direction = \"horizontal\",\n",
" legend_background = element_rect(fill = \"white\", color = \"gray\"),\n",
" figure_size = (10, 6.18)\n",
" )\n",
")"
],
"id": "winter-medals-by-sport",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Row - Medals by year {height=\"40%\"}\n",
"\n",
"::: {.card title=\"Medals by year\"}\n",
"Due to World War II, no olympic games were held in 1940 and 1944.\n"
],
"id": "951a5ff6"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: winter-medals-by-year\n",
"\n",
"# Count the occurrences of each medal per year\n",
"winter_olympics_count = winter_olympics.groupby([\"year\", \"medal\"], observed=True).size().reset_index(name = \"n\")\n",
"\n",
"# Plot\n",
"(\n",
" ggplot(winter_olympics_count, aes(x = \"year\", y = \"n\", color = \"medal\")) +\n",
" geom_point(size = 0.5) +\n",
" geom_line() +\n",
" guides(color = guide_legend(reverse = True)) + \n",
" scale_x_continuous(breaks = range(1896, 2020, 8)) +\n",
" labs(x = \"Year\", y = \"\", color = \"Medal\") +\n",
" theme_minimal() +\n",
" theme(\n",
" legend_position = \"inside\",\n",
" legend_position_inside = (0.9, 0.2),\n",
" legend_direction = \"horizontal\",\n",
" legend_background = element_rect(fill = \"white\", color = \"gray\"),\n",
" figure_size = (10, 3)\n",
" )\n",
")"
],
"id": "winter-medals-by-year",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
":::\n",
"\n",
"## Column - Medals by country {width=\"35%\"}\n",
"\n",
"### Row - Value boxes {height=\"30%\"}\n"
],
"id": "85a3d3a2"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: winter-calculate-most-medals\n",
"\n",
"# Filter for gold medals\n",
"gold_medals = winter_olympics[winter_olympics['medal'] == 'Gold']\n",
"# Group by team and count gold medals\n",
"gold_medal_counts = gold_medals.groupby('team').size()\n",
"# Find the team with the most gold medals\n",
"most_gold_medals = gold_medal_counts.idxmax()\n",
"count_most_gold_medals = gold_medal_counts.max()\n",
"\n",
"# Filter for silver medals\n",
"silver_medals = winter_olympics[winter_olympics['medal'] == 'Silver']\n",
"# Group by team and count silver medals\n",
"silver_medal_counts = silver_medals.groupby('team').size()\n",
"# Find the team with the most silver medals\n",
"most_silver_medals = silver_medal_counts.idxmax()\n",
"count_most_silver_medals = silver_medal_counts.max()\n",
"\n",
"# Filter for bronze medals\n",
"bronze_medals = winter_olympics[winter_olympics['medal'] == 'Bronze']\n",
"# Group by team and count bronze medals\n",
"bronze_medal_counts = bronze_medals.groupby('team').size()\n",
"# Find the team with the most bronze medals\n",
"most_bronze_medals = bronze_medal_counts.idxmax()\n",
"count_most_bronze_medals = bronze_medal_counts.max()"
],
"id": "winter-calculate-most-medals",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"::: {.valuebox icon=\"award-fill\" color=\"#d4af37\"}\n",
"Most golds:\n",
"\n",
"`{python} str(count_most_gold_medals)`\n",
"\n",
"`{python} most_gold_medals`\n",
":::\n",
"\n",
"::: {.valuebox icon=\"award-fill\" color=\"#c0c0c0\"}\n",
"Most silvers:\n",
"\n",
"`{python} str(count_most_silver_medals)`\n",
"\n",
"`{python} most_silver_medals`\n",
":::\n",
"\n",
"::: {.valuebox icon=\"award-fill\" color=\"#cd7f32\"}\n",
"Most bronzes:\n",
"\n",
"`{python} str(count_most_bronze_medals)`\n",
"\n",
"`{python} most_bronze_medals`\n",
":::\n",
"\n",
"### Row - Tabsets of tables {.tabset height=\"70%\"}\n"
],
"id": "c8b34c84"
},
{
"cell_type": "code",
"metadata": {
"title": "Medals by country"
},
"source": [
"#| label: winter-medals-by-country\n",
"\n",
"# Count the occurrences of each medal per team\n",
"winter_olympics_count = winter_olympics.groupby([\"team\", \"medal\"]).size().reset_index(name=\"n\")\n",
"\n",
"# Pivot olympics_count to get medals as columns\n",
"winter_olympics_pivot = winter_olympics_count.pivot_table(index = \"team\", columns = \"medal\", values = \"n\", fill_value = 0)\n",
"\n",
"# Calculate the total number of medals\n",
"winter_olympics_pivot[\"Total\"] = winter_olympics_pivot[[\"Bronze\", \"Gold\", \"Silver\"]].sum(axis=1)\n",
"\n",
"# Reset the index and rearrange columns\n",
"winter_olympics_pivot = winter_olympics_pivot.reset_index()\n",
"winter_olympics_pivot = winter_olympics_pivot[[\"team\", \"Gold\", \"Silver\", \"Bronze\", \"Total\"]]\n",
"\n",
"# Sort by Total medals, then team\n",
"winter_olympics_sorted_descending = winter_olympics_pivot.sort_values(by=[\"Total\", \"team\"], ascending=[False, True])\n",
"winter_olympics_sorted_ascending = winter_olympics_pivot.sort_values(by=[\"Total\", \"team\"], ascending=[True, True])\n",
"\n",
"# Remove Total\n",
"winter_olympics_sorted_descending = winter_olympics_sorted_descending[[\"team\", \"Gold\", \"Silver\", \"Bronze\"]]\n",
"winter_olympics_sorted_ascending = winter_olympics_sorted_ascending[[\"team\", \"Gold\", \"Silver\", \"Bronze\"]]\n",
"\n",
"# Rename the team column to Team\n",
"winter_olympics_sorted_descending.rename(columns={\"team\": \"Team\"}, inplace=True)\n",
"winter_olympics_sorted_ascending.rename(columns={\"team\": \"Team\"}, inplace=True)\n",
"\n",
"# Find top and bottom 30\n",
"winter_olympics_sorted_descending_top30 = winter_olympics_sorted_descending.head(30)\n",
"winter_olympics_sorted_descending_top30.reset_index(drop=True, inplace=True)\n",
"winter_olympics_sorted_ascending_bottom30 = winter_olympics_sorted_ascending.head(30)\n",
"winter_olympics_sorted_ascending_bottom30.reset_index(drop=True, inplace=True)"
],
"id": "winter-medals-by-country",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"::: {.card title=\"Top 30 total medals\"}\n",
"Teams sorted in descending order of total medals.\n"
],
"id": "7a35165b"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: winter-top-30-medals\n",
"(\n",
" gt.GT(winter_olympics_sorted_descending_top30).data_color(\n",
" columns=[\"Gold\", \"Silver\", \"Bronze\"],\n",
" palette=\"Oranges\"\n",
" )\n",
")"
],
"id": "winter-top-30-medals",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
":::\n",
"\n",
"::: {.card title=\"Bottom 30 total medals\"}\n",
"Teams sorted in ascending order of total medals.\n"
],
"id": "1273cee1"
},
{
"cell_type": "code",
"metadata": {},
"source": [
"#| label: winter-bottom-30-medals\n",
"(\n",
" gt.GT(winter_olympics_sorted_ascending_bottom30).data_color(\n",
" columns=[\"Gold\", \"Silver\", \"Bronze\"],\n",
" palette=\"Blues\"\n",
" )\n",
")"
],
"id": "winter-bottom-30-medals",
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
":::"
],
"id": "bdf7e951"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}