Py.Cafe

sylvie.bartusek/

figure-friday-week40

Eurovision Songs

DocsPricing
  • data/
  • app.py
  • requirements.txt
app.py
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
# Vizro is an open-source toolkit for creating modular data visualization applications.
# check out https://github.com/mckinsey/vizro for more info about Vizro
# and checkout https://vizro.readthedocs.io/en/stable/ for documentation.

import vizro.plotly.express as px
from vizro import Vizro
import vizro.models as vm
import pandas as pd


# read eurovision data
df = pd.read_csv("https://raw.githubusercontent.com/plotly/Figure-Friday/refs/heads/main/2024/week-40/contestants.csv")
# df['year'] = pd.to_datetime(df['year'], format='%Y') # Format the Year column into datetime
df = df[df['place_final']>=1]

df_mean = df[df['points_final']>=0]
df_mean = df_mean[['to_country', 'points_final']]
df_mean.groupby(["to_country"]).sum()

# CONTESTANTS.CSV HAS THE FOLLOWING:
#       year
#       to_country_id
#       to_country
#       performer
#       song
#       sf_num
#       running_final
#       running_sf
#       place_final
#       points_final
#       place_sf
#       points_sf
#       points_tele_final
#       points_jury_final
#       points_tele_sf
#       points_jury_sf
#       composers
#       lyricists
#       lyrics
#       youtube_url


# remove all entries where there is no place final 
# df = df[df['points_jury_final']>=1]
df = df[df['year']!=1956]



#map for final placements
fig_map = px.choropleth(
    df, 
    locationmode="country names",
    locations="to_country", 
    color="place_final",
    scope="europe",
    # animation_frame="year",
    # range_color=(1, 25),
    color_continuous_scale="orrd"
)

hist = px.histogram(df_mean, x="points_final", y="to_country")


#map for semi-final placements
fig_map2 = px.choropleth(
    df, 
    locationmode="country names",
    locations="to_country", 
    color="points_jury_final",
    scope="europe",
    # animation_frame="year",
    # range_color=(1, 25),
    color_continuous_scale="orrd"
)

page = vm.Page(
    title="Eurovision Countries Final Jury Points vs Television Viewer Points",
    # layout=vm.Layout(grid=[ [0, 1], 
    #                         [2, 2], 
    #                         [2, 2], 
    #                         [3, 3], 
    #                         [3, 3]], 
    #             row_min_height="140px"),
    components=[
    #     vm.Card(
    #         text="""
    #             ### What is Vizro?
    #             An open-source toolkit for creating modular data visualization applications.
                
    #             Rapidly self-serve the assembly of customized dashboards in minutes - without the need for advanced coding or design experience - to create flexible and scalable, Python-enabled data visualization applications."""
    #     ),
        # vm.Card(
        #     text="""
        #         ### Winner's performance:""",
        #     href="map.youtube_url",
        # ),

        vm.Graph(id="map1", figure=fig_map), 
        vm.Graph(id="hist", figure=hist)
        # vm.Graph(id="map2", figure=fig_map2)
    ],

    controls=[
        vm.Filter(column="year", selector=vm.Slider(min=1957, max=2023, step=1))
    ],
)

dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()