Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
|
|
|
|
4 |
def assign_color(count):
|
5 |
if count <= 10:
|
6 |
return '1-10'
|
@@ -14,6 +16,7 @@ def assign_color(count):
|
|
14 |
return '500-1000'
|
15 |
else:
|
16 |
return '>1000'
|
|
|
17 |
# Country mapping dictionary
|
18 |
country_mapping = {
|
19 |
'United States': 'USA',
|
@@ -121,6 +124,7 @@ country_mapping = {
|
|
121 |
'Maldives': 'MDV'
|
122 |
}
|
123 |
|
|
|
124 |
df_movies = pd.read_csv('movie_after_cleaning.csv')
|
125 |
df_tv_series = pd.read_csv('series_after_cleaning.csv')
|
126 |
|
@@ -141,7 +145,11 @@ def create_genre_bar_chart(df, title):
|
|
141 |
genre_counts = df_exploded['genre'].value_counts().reset_index()
|
142 |
genre_counts.columns = ['genre', 'count']
|
143 |
genre_counts = genre_counts.head(10) # Top 10 genres
|
144 |
-
fig = px.bar(genre_counts, x='count', y='genre', orientation='h', title=title
|
|
|
|
|
|
|
|
|
145 |
return fig
|
146 |
|
147 |
# Function to create choropleth map
|
@@ -165,11 +173,22 @@ def create_country_map(df, title):
|
|
165 |
color_discrete_sequence=['#7FFF00', '#FFD700', '#FFA500', '#FF4500', '#DC143C', '#8B0000'],
|
166 |
category_orders={"color": ['1-10', '10-50', '50-100', '100-500', '500-1000', '>1000']})
|
167 |
|
|
|
|
|
|
|
|
|
|
|
168 |
return fig
|
169 |
|
170 |
# Function to create rating distribution box chart
|
171 |
def create_rating_box_chart(df, title):
|
172 |
-
fig = px.box(df, x="rating", points="all", title=title
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
return fig
|
174 |
|
175 |
# Streamlit app
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
+
|
5 |
+
# Function to assign color based on count
|
6 |
def assign_color(count):
|
7 |
if count <= 10:
|
8 |
return '1-10'
|
|
|
16 |
return '500-1000'
|
17 |
else:
|
18 |
return '>1000'
|
19 |
+
|
20 |
# Country mapping dictionary
|
21 |
country_mapping = {
|
22 |
'United States': 'USA',
|
|
|
124 |
'Maldives': 'MDV'
|
125 |
}
|
126 |
|
127 |
+
# Load your dataframes (replace with actual CSV filenames)
|
128 |
df_movies = pd.read_csv('movie_after_cleaning.csv')
|
129 |
df_tv_series = pd.read_csv('series_after_cleaning.csv')
|
130 |
|
|
|
145 |
genre_counts = df_exploded['genre'].value_counts().reset_index()
|
146 |
genre_counts.columns = ['genre', 'count']
|
147 |
genre_counts = genre_counts.head(10) # Top 10 genres
|
148 |
+
fig = px.bar(genre_counts, x='count', y='genre', orientation='h', title=title,
|
149 |
+
labels={'count': 'Count', 'genre': 'Genre'},
|
150 |
+
color_discrete_sequence=['#FFA07A'])
|
151 |
+
fig.update_traces(marker_line_color='rgb(8,48,107)', marker_line_width=1.5, opacity=0.6)
|
152 |
+
fig.update_layout(title_font_size=20, title_font_family='Arial', title_font_color='#00308F')
|
153 |
return fig
|
154 |
|
155 |
# Function to create choropleth map
|
|
|
173 |
color_discrete_sequence=['#7FFF00', '#FFD700', '#FFA500', '#FF4500', '#DC143C', '#8B0000'],
|
174 |
category_orders={"color": ['1-10', '10-50', '50-100', '100-500', '500-1000', '>1000']})
|
175 |
|
176 |
+
fig.update_geos(showcoastlines=True, coastlinecolor="LightBlue", showland=True, landcolor="LightGreen",
|
177 |
+
showocean=True, oceancolor="LightBlue", showlakes=True, lakecolor="LightBlue",
|
178 |
+
showrivers=True, rivercolor="LightBlue")
|
179 |
+
|
180 |
+
fig.update_layout(title_font_size=20, title_font_family='Arial', title_font_color='#00308F')
|
181 |
return fig
|
182 |
|
183 |
# Function to create rating distribution box chart
|
184 |
def create_rating_box_chart(df, title):
|
185 |
+
fig = px.box(df, x="rating", points="all", title=title,
|
186 |
+
labels={'rating': 'Rating'},
|
187 |
+
boxmean=True,
|
188 |
+
orientation='h',
|
189 |
+
color_discrete_sequence=['#FF6347'])
|
190 |
+
fig.update_traces(marker_line_color='rgb(8,48,107)', marker_line_width=1.5, opacity=0.6)
|
191 |
+
fig.update_layout(title_font_size=20, title_font_family='Arial', title_font_color='#00308F')
|
192 |
return fig
|
193 |
|
194 |
# Streamlit app
|