-
Notifications
You must be signed in to change notification settings - Fork 5
/
02_Marche_du_stream_en_2021.py
283 lines (193 loc) · 11.8 KB
/
02_Marche_du_stream_en_2021.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
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
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import plotly.express as px
import numpy as np
import seaborn as sns
from PIL import Image
# Afficher notre logo dans le sidebar
notre_logo = Image.open('STREAMLIT/images/logo.png')
image_container = st.container()
with image_container:
st.sidebar.image(notre_logo, width=300)
st.markdown("# LE MARCHÉ DU STREAM ACTUEL 🎧")
st.subheader('Les talents du moment...et jeunes talents à venir')
#st.sidebar.markdown("# Les talents du moment 🎼")
# Importer le dataset TOP 2000 : Janvier 2017 à dec 2021
df_top_200 = pd.read_csv("STREAMLIT/datasets/top_200.csv", sep = ",")
# Importer le dataset Amine :
df_dataset = pd.read_csv("STREAMLIT/datasets/dataset.csv", sep = ",")
# Afficher le dataframe
# st.write(df_top_200)
# CREER DES TAB
tab1, tab2, tab3, tab4 = st.tabs(['TOP 10 ARTISTES', 'TOP 10 MORCEAUX', 'BOX PLOT', 'TOP 10 PROGRESSION'])
# TRAVAILLER SUR LES TAB
with tab1 :
st.subheader('Artistes les plus streamés sur Spotify en 2021')
st.markdown('Par volume de stream et par volume de titre')
df3 = df_top_200
# Sélection du df sur l'année 2021
df3['date'] = pd.to_datetime(df3['date'])
mask = df3['date'] > '2020-12-31'
df3 = df3[mask].copy()
# Constitue 2 DF : un global et un france uniquement
df3_france = df3[df3['region'] =='France'].copy()
df_grouped_france_titre = df3_france.groupby('title').agg({'streams': 'max', 'artist': lambda x: x.iloc[0]}).reset_index()
df3_global = df3[df3['region']=='Global'].copy()
df_grouped_global_titre = df3_global.groupby('title').agg({'streams': 'max', 'artist': lambda x: x.iloc[0]}).reset_index()
# création de la grille horizontale
col1, col2 = st.columns(2)
with col1 :
# Détermination du dataframe pour le graphique TOP10 France par Artiste en volume de stream avec volume de titre
df_grouped_france_artiste = df_grouped_france_titre.groupby('artist').agg({'streams': 'sum'})
df_grouped_france_artiste = df_grouped_france_artiste.sort_values(by='streams', ascending=False)
df4 = df_grouped_france_artiste.head(10).copy().reset_index()
df5 = df_grouped_france_titre[df_grouped_france_titre['artist'].isin(df4['artist'])]
df5 = df5.sort_values(by='streams', ascending=False)
df6 = df5.groupby('artist').agg({'title': 'count', 'streams': 'sum'}).reset_index()
df6 = df6.rename(columns={'title': 'nbre_de_titre', 'streams': 'total_stream'})
df6 = df6.sort_values(by='total_stream', ascending=False)
# Créer le graphique
top10FR = px.bar(df6, x='artist', y='total_stream', color='nbre_de_titre')
top10FR.update_layout(
title='TOP 10 des artistes écoutés en FRANCE',
xaxis_title='',
yaxis_title='Volume de Stream')
# Afficher le graphique
st.plotly_chart(top10FR)
with col2 :
# Détermination du dataframe pour le graphique TOP10 MONDE par Artiste en volume de stream avec volume de titre
df_grouped_global_artiste = df_grouped_global_titre.groupby('artist').agg({'streams': 'sum'})
df_grouped_global_artiste = df_grouped_global_artiste.sort_values(by='streams', ascending=False)
df7 = df_grouped_global_artiste.head(10).copy().reset_index()
df8 = df_grouped_global_titre[df_grouped_global_titre['artist'].isin(df7['artist'])]
df8 = df8.sort_values(by='streams', ascending=False)
df9 = df8.groupby('artist').agg({'title': 'count', 'streams': 'sum'}).reset_index()
df9 = df9.rename(columns={'title': 'nbre_de_titre', 'streams': 'total_stream'})
df9 = df9.sort_values(by='total_stream', ascending=False)
# Créer le graphique
top10GB = px.bar(df9, x='artist', y='total_stream', color='nbre_de_titre')
top10GB.update_layout(
title='TOP 10 des artistes écoutés dans le MONDE',
xaxis_title='',
yaxis_title='Volume de Stream')
# Afficher le graphique
st.plotly_chart(top10GB)
with tab2 :
st.subheader('Record de streams sur une journée en 2021 par titre')
# création de la grille horizontale
col1, col2 = st.columns(2)
with col1 :
df3 = df_top_200
# Sélection du df sur l'année 2021
df3['date'] = pd.to_datetime(df3['date'])
mask = df3['date'] > '2020-12-31'
df3 = df3[mask].copy()
df3_france = df3[df3['region'] =='France'].copy()
df_grouped_france_titre = df3_france.groupby('title').agg({'streams': 'max', 'artist': lambda x: x.iloc[0]}).reset_index()
# Filtrer les 10 titres ayant la valeur de stream maximale et trier les données
df_grouped_france_titre_sorted = df_grouped_france_titre.sort_values(by= 'streams', ascending=False).head(10)
#st.write(df_grouped_france_titre_sorted)
# Créer le graphique
fig6, ax = plt.subplots(figsize=(10, 6))
# Ajouter les barres pour les streams
fig6 = px.bar(df_grouped_france_titre_sorted, x = 'title', y ='streams', color = 'artist')
fig6.update_layout(title='TOP 10 streamés en France', xaxis_title='Titles',yaxis_title='Volume de Stream')
# Afficher le graphique
st.plotly_chart(fig6)
with col2 :
df3 = df_top_200
# Sélection du df sur l'année 2021
df3['date'] = pd.to_datetime(df3['date'])
mask = df3['date'] > '2020-12-31'
df3 = df3[mask].copy()
df3_global = df3[df3['region']=='Global'].copy()
df_grouped_global_titre = df3_global.groupby('title').agg({'streams': 'max', 'artist': lambda x: x.iloc[0]}).reset_index()
# Filtrer les 10 titres ayant la valeur de stream maximale et trier les données
df_grouped_global_titre_sorted = df_grouped_global_titre.sort_values(by= 'streams', ascending=False).head(10)
# Créer le graphique
fig5, ax = plt.subplots(figsize=(10, 6))
# Ajouter les barres pour les streams
fig5 = px.bar(df_grouped_global_titre_sorted, x = 'title', y ='streams', color = 'artist')
fig5.update_layout(title='TOP 10 streamés dans le Monde', xaxis_title='Titles',yaxis_title='Volume de Stream')
# Afficher le graphique
st.plotly_chart(fig5)
with tab3 :
st.subheader('Distribution des records de streams journalier en 2021 par artiste (dernier quartile uniquement)')
#st.markdown('Une pépite en france = Entre 230 et 350 stream avec une forte progression')
#st.markdown('Une pépite total monde = Entre 2,2M et 3M stream avec une forte progression')
df3 = df_top_200
# Sélection du df sur l'année 2021
df3['date'] = pd.to_datetime(df3['date'])
mask = df3['date'] > '2020-12-31'
df3 = df3[mask].copy()
# création de la grille horizontale
col1, col2 = st.columns(2)
with col1 :
Q3_FR = df_grouped_france_artiste['streams'].quantile(0.75)
df_stat_frQ3 = df_grouped_france_artiste[df_grouped_france_artiste['streams']>Q3_FR]
# BOXPLOT sur la distribution du stream pour le df France 2021, minimum fixé au Q3
#fig, ax = plt.subplots(figsize=(10, 6))
fig1 = px.box(df_stat_frQ3, x='streams', orientation='h', boxmode='overlay', color_discrete_sequence=['blue'], title='Streams en France')
# Afficher le graphique plotly
st.plotly_chart(fig1)
with col2 :
df3_global = df3[df3['region']=='Global'].copy()
df_grouped_global_artiste = df3_global.groupby('title').agg({'streams': 'max', 'artist': lambda x: x.iloc[0]}).reset_index()
Q3_GB = df_grouped_global_titre['streams'].quantile(0.75)
df_stat_gbQ3 = df_grouped_global_artiste[df_grouped_global_artiste['streams']>Q3_GB]
fig2 = px.box(df_stat_gbQ3, x='streams', orientation='h', boxmode='overlay', color_discrete_sequence=['blue'], title='Streams dans le Monde')
# Afficher le graphique plotly
st.plotly_chart(fig2)
with tab4 :
st.subheader('Artistes avec la plus forte augmentation de streams en 2021')
# création de la grille horizontale
col1, col2 = st.columns(2)
# Sélection du df sur l'année 2021
df_top_200['date'] = pd.to_datetime(df_top_200['date'])
mask = df_top_200['date'] > '2020-12-31'
annee_2021 = df_top_200[mask].copy()
with col1 :
# On selectionne que les artiste écoutés en FRANCE
annee_2021_FR = annee_2021[annee_2021['region'] == 'France']
# Filtrer les artistes avec 'NEW_ENTRY' dans la colonne 'trend'
new_entry_artists_FR = annee_2021_FR[annee_2021_FR['trend'] == 'NEW_ENTRY']
# Trouver la valeur maximale de streams
title_max = annee_2021_FR.groupby('title').agg({'streams': 'max', 'artist': lambda x: x.iloc[0]}).reset_index()
# Merge new entry artists et title max
df_merge_FR = pd.merge(new_entry_artists_FR, title_max, how="left", on='title')
# Garder uniquement les colonnes souhaitées
df_merge_FR = df_merge_FR[['title', 'region', 'artist_x', 'streams_x', 'streams_y']]
# Renommer les colonnes
df_merge_FR = df_merge_FR.rename(columns={'streams_x': 'entry_streams', 'streams_y': 'streams_max', 'artist_x' : 'artist' })
# On regroupe par artiste
df_merge_groupby_artiste_FR = df_merge_FR.groupby('artist').agg({'entry_streams': 'sum', 'streams_max' : 'sum' }).reset_index()
# On ajoute une colonne avec la différence
df_merge_groupby_artiste_FR['difference'] = df_merge_groupby_artiste_FR['streams_max'] - df_merge_groupby_artiste_FR['entry_streams']
df_merge_groupby_artiste_FR_sorted = df_merge_groupby_artiste_FR.sort_values('difference', ascending=False).head(10)
# Graphique
Top_evolution_FR = px.bar(df_merge_groupby_artiste_FR_sorted, x='artist', y='difference', color='artist')
Top_evolution_FR.update_layout(title='TOP 10 streamés en France',xaxis_title='',yaxis_title='Volume de Streams',showlegend=False)
st.plotly_chart(Top_evolution_FR)
with col2 :
# On selectionne que les artiste écoutés GLOBAL
annee_2021_GB = annee_2021[annee_2021['region'] == 'Global']
# Filtrer les artistes avec 'NEW_ENTRY' dans la colonne 'trend'
new_entry_artists_GB = annee_2021_GB[annee_2021_GB['trend'] == 'NEW_ENTRY']
# Trouver la valeur maximale de streams
title_max = annee_2021_GB.groupby('title').agg({'streams': 'max', 'artist': lambda x: x.iloc[0]}).reset_index()
# Merge new entry artists et title max
df_merge_GB = pd.merge(new_entry_artists_GB, title_max, how="left", on='title')
# Garder uniquement les colonnes souhaitées
df_merge_GB = df_merge_GB[['title', 'region', 'artist_x', 'streams_x', 'streams_y']]
# Renommer les colonnes
df_merge_GB = df_merge_GB.rename(columns={'streams_x': 'entry_streams', 'streams_y': 'streams_max', 'artist_x' : 'artist' })
# On regroupe par artiste
df_merge_groupby_artiste_GB = df_merge_GB.groupby('artist').agg({'entry_streams': 'sum', 'streams_max' : 'sum' }).reset_index()
# On ajoute une colonne avec la différence
df_merge_groupby_artiste_GB['difference'] = df_merge_groupby_artiste_GB['streams_max'] - df_merge_groupby_artiste_GB['entry_streams']
df_merge_groupby_artiste_GB_sorted = df_merge_groupby_artiste_GB.sort_values('difference', ascending=False).head(10)
# Graphique
Top_evolution_GB = px.bar(df_merge_groupby_artiste_GB_sorted, x='artist', y='difference', color='artist')
Top_evolution_GB.update_layout(title='TOP 10 streamés dans le Monde',xaxis_title='',yaxis_title='Volume de Streams',showlegend=False)
st.plotly_chart(Top_evolution_GB)