# 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()