Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,41 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
# Load your dataframes
|
6 |
df_tv_series= pd.read_csv('series_after_cleaning.csv')
|
7 |
df_movies= pd.read_csv('movie_after_cleaning.csv')
|
@@ -15,6 +50,7 @@ df_tv_series['country'] = df_tv_series['country'].str.split(',')
|
|
15 |
def create_treemap(df, title):
|
16 |
fig = px.treemap(df, path=['parentalguide'], title=title)
|
17 |
return fig
|
|
|
18 |
def create_genre_bar_chart(df, title):
|
19 |
# Explode the genre column to count each genre separately
|
20 |
df_exploded = df.explode('genre')
|
@@ -23,12 +59,25 @@ def create_genre_bar_chart(df, title):
|
|
23 |
genre_counts = genre_counts.head(10) # Get top 10 genres
|
24 |
fig = px.bar(genre_counts, x='count', y='genre', orientation='h', title=title)
|
25 |
return fig
|
|
|
26 |
def create_country_map(df, title):
|
27 |
-
|
|
|
|
|
28 |
country_counts.columns = ['country', 'count']
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
return fig
|
33 |
|
34 |
# Streamlit app
|
|
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
|
5 |
+
country_mapping = {
|
6 |
+
'United States': 'USA',
|
7 |
+
'United Kingdom': 'GBR',
|
8 |
+
'France': 'FRA',
|
9 |
+
'Canada': 'CAN',
|
10 |
+
'Germany': 'DEU',
|
11 |
+
'Japan': 'JPN',
|
12 |
+
'India': 'IND',
|
13 |
+
'Australia': 'AUS',
|
14 |
+
'China': 'CHN',
|
15 |
+
'Italy': 'ITA',
|
16 |
+
'Spain': 'ESP',
|
17 |
+
'Mexico': 'MEX',
|
18 |
+
'Hong Kong': 'HKG',
|
19 |
+
'Sweden': 'SWE',
|
20 |
+
'Denmark': 'DNK',
|
21 |
+
'New Zealand': 'NZL',
|
22 |
+
'Belgium': 'BEL',
|
23 |
+
'South Korea': 'KOR',
|
24 |
+
'Ireland': 'IRL',
|
25 |
+
'Czech Republic': 'CZE',
|
26 |
+
'Switzerland': 'CHE',
|
27 |
+
'Hungary': 'HUN',
|
28 |
+
'Norway': 'NOR',
|
29 |
+
'United Arab Emirates': 'ARE',
|
30 |
+
'Netherlands': 'NLD',
|
31 |
+
'South Africa': 'ZAF',
|
32 |
+
'Poland': 'POL',
|
33 |
+
'Austria': 'AUT',
|
34 |
+
'Turkey': 'TUR'
|
35 |
+
}
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
# Load your dataframes
|
41 |
df_tv_series= pd.read_csv('series_after_cleaning.csv')
|
42 |
df_movies= pd.read_csv('movie_after_cleaning.csv')
|
|
|
50 |
def create_treemap(df, title):
|
51 |
fig = px.treemap(df, path=['parentalguide'], title=title)
|
52 |
return fig
|
53 |
+
|
54 |
def create_genre_bar_chart(df, title):
|
55 |
# Explode the genre column to count each genre separately
|
56 |
df_exploded = df.explode('genre')
|
|
|
59 |
genre_counts = genre_counts.head(10) # Get top 10 genres
|
60 |
fig = px.bar(genre_counts, x='count', y='genre', orientation='h', title=title)
|
61 |
return fig
|
62 |
+
|
63 |
def create_country_map(df, title):
|
64 |
+
# Explode the country column to count each country separately
|
65 |
+
df_exploded = df.explode('country')
|
66 |
+
country_counts = df_exploded['country'].value_counts().reset_index()
|
67 |
country_counts.columns = ['country', 'count']
|
68 |
+
|
69 |
+
# Map country names to ISO codes
|
70 |
+
country_counts['country'] = country_counts['country'].map(country_mapping)
|
71 |
+
|
72 |
+
fig = px.choropleth(country_counts,
|
73 |
+
locations="country",
|
74 |
+
color="count",
|
75 |
+
hover_name="country",
|
76 |
+
title=title,
|
77 |
+
projection="natural earth",
|
78 |
+
color_continuous_scale='Viridis')
|
79 |
+
fig.update_layout(template='plotly_dark', font=dict(color='yellow'))
|
80 |
+
|
81 |
return fig
|
82 |
|
83 |
# Streamlit app
|