Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -124,6 +124,24 @@ def create_treemap(df, title):
|
|
124 |
fig = px.treemap(df, path=['parentalguide'], title=title)
|
125 |
return fig
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
# Function to create genre bar chart
|
128 |
def create_genre_bar_chart(df, title):
|
129 |
df_exploded = df.explode('genre')
|
@@ -192,7 +210,7 @@ if selection_movies:
|
|
192 |
st.plotly_chart(create_country_map(df_movies, 'Global Distribution of Movies'), use_container_width=True)
|
193 |
with col2_2:
|
194 |
st.plotly_chart(create_rating_box_chart(df_movies, 'Rating Distribution - Movies'), use_container_width=True)
|
195 |
-
|
196 |
elif selection_tv_series:
|
197 |
st.subheader('TV Series')
|
198 |
display_summary_metrics(df_tv_series)
|
@@ -206,3 +224,4 @@ elif selection_tv_series:
|
|
206 |
st.plotly_chart(create_country_map(df_tv_series, 'Global Distribution of TV Series'), use_container_width=True)
|
207 |
with col2_2:
|
208 |
st.plotly_chart(create_rating_box_chart(df_tv_series, 'Rating Distribution - TV Series'), use_container_width=True)
|
|
|
|
124 |
fig = px.treemap(df, path=['parentalguide'], title=title)
|
125 |
return fig
|
126 |
|
127 |
+
def create_best_genres_line_chart(df, title):
|
128 |
+
# Combine genres data from both movies and TV series
|
129 |
+
df_genres = df.explode('genre')
|
130 |
+
|
131 |
+
# Group by year and genre to count occurrences
|
132 |
+
genre_counts = df_genres.groupby(['year', 'genre']).size().reset_index(name='count')
|
133 |
+
|
134 |
+
# Find the most popular genre by count for each year
|
135 |
+
idx = genre_counts.groupby(['year'])['count'].transform(max) == genre_counts['count']
|
136 |
+
best_genres = genre_counts[idx]
|
137 |
+
|
138 |
+
# Plotly line chart for best genres over the years
|
139 |
+
fig_best_genres = px.line(best_genres, x='year', y='count', color='genre', title=title)
|
140 |
+
fig_best_genres.update_layout(xaxis_title='Year', yaxis_title='Number of Works', legend_title='Genre')
|
141 |
+
|
142 |
+
return fig_best_genres
|
143 |
+
|
144 |
+
|
145 |
# Function to create genre bar chart
|
146 |
def create_genre_bar_chart(df, title):
|
147 |
df_exploded = df.explode('genre')
|
|
|
210 |
st.plotly_chart(create_country_map(df_movies, 'Global Distribution of Movies'), use_container_width=True)
|
211 |
with col2_2:
|
212 |
st.plotly_chart(create_rating_box_chart(df_movies, 'Rating Distribution - Movies'), use_container_width=True)
|
213 |
+
st.plotly_chart(create_best_genres_line_chart(df_movies, 'Best Genres Over the Years - Movies'), use_container_width=True)
|
214 |
elif selection_tv_series:
|
215 |
st.subheader('TV Series')
|
216 |
display_summary_metrics(df_tv_series)
|
|
|
224 |
st.plotly_chart(create_country_map(df_tv_series, 'Global Distribution of TV Series'), use_container_width=True)
|
225 |
with col2_2:
|
226 |
st.plotly_chart(create_rating_box_chart(df_tv_series, 'Rating Distribution - TV Series'), use_container_width=True)
|
227 |
+
st.plotly_chart(create_best_genres_line_chart(df_tv_series, 'Best Genres Over the Years - TV Series'), use_container_width=True)
|