File size: 3,612 Bytes
90a6c5f
5a0a701
 
90a6c5f
0941b5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a0a701
4d9b242
 
50f339f
53d94e8
 
6da5cf7
 
90a6c5f
5a0a701
 
 
 
0941b5e
c5ff652
 
 
 
 
 
 
0488555
0941b5e
514acd5
0941b5e
 
 
514acd5
0941b5e
 
 
 
 
 
 
 
 
 
 
 
 
514acd5
90a6c5f
5a0a701
 
90a6c5f
4d9b242
 
90a6c5f
dcbc569
514acd5
dcbc569
4d9b242
 
 
dcbc569
4d9b242
 
 
dcbc569
 
 
 
 
a178b93
514acd5
dcbc569
280aeca
a178b93
514acd5
0488555
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
import streamlit as st
import pandas as pd
import plotly.express as px

country_mapping = {
    'United States': 'USA',
    'United Kingdom': 'GBR',
    'France': 'FRA',
    'Canada': 'CAN',
    'Germany': 'DEU',
    'Japan': 'JPN',
    'India': 'IND',
    'Australia': 'AUS',
    'China': 'CHN',
    'Italy': 'ITA',
    'Spain': 'ESP',
    'Mexico': 'MEX',
    'Hong Kong': 'HKG',
    'Sweden': 'SWE',
    'Denmark': 'DNK',
    'New Zealand': 'NZL',
    'Belgium': 'BEL',
    'South Korea': 'KOR',
    'Ireland': 'IRL',
    'Czech Republic': 'CZE',
    'Switzerland': 'CHE',
    'Hungary': 'HUN',
    'Norway': 'NOR',
    'United Arab Emirates': 'ARE',
    'Netherlands': 'NLD',
    'South Africa': 'ZAF',
    'Poland': 'POL',
    'Austria': 'AUT',
    'Turkey': 'TUR'
}




# Load your dataframes
df_tv_series= pd.read_csv('series_after_cleaning.csv')
df_movies= pd.read_csv('movie_after_cleaning.csv')

df_movies['genre'] = df_movies['genre'].str.split(',')
df_tv_series['genre'] = df_tv_series['genre'].str.split(',')
df_movies['country'] = df_movies['country'].str.split(',')
df_tv_series['country'] = df_tv_series['country'].str.split(',')

# Function to generate treemap
def create_treemap(df, title):
    fig = px.treemap(df, path=['parentalguide'], title=title)
    return fig
    
def create_genre_bar_chart(df, title):
    # Explode the genre column to count each genre separately
    df_exploded = df.explode('genre')
    genre_counts = df_exploded['genre'].value_counts().reset_index()
    genre_counts.columns = ['genre', 'count']
    genre_counts = genre_counts.head(10)  # Get top 10 genres
    fig = px.bar(genre_counts, x='count', y='genre', orientation='h', title=title)
    return fig
    
def create_country_map(df, title):
    # Explode the country column to count each country separately
    df_exploded = df.explode('country')
    country_counts = df_exploded['country'].value_counts().reset_index()
    country_counts.columns = ['country', 'count']
    
    # Map country names to ISO codes
    country_counts['country'] = country_counts['country'].map(country_mapping)
    
    fig = px.choropleth(country_counts, 
                        locations="country",
                        color="count",
                        hover_name="country",
                        title=title,
                        projection="natural earth",
                        color_continuous_scale='Viridis')
    fig.update_layout(template='plotly_dark', font=dict(color='yellow'))
    
    return fig

# Streamlit app
st.title('Parental Guide Treemaps')

# Split into two columns
col1, col2 = st.columns(2)

# Initialize variable for selection
selection = 'Movies'

# Add buttons in each column
with col1:
    if st.button('Movies'):
        selection = 'Movies'

with col2:
    if st.button('TV Series'):
        selection = 'TV Series'

# Display the corresponding treemap in the center
if selection == 'Movies':
    st.plotly_chart(create_treemap(df_movies, 'Parental Guide - Movies'), use_container_width=True)
    st.plotly_chart(create_genre_bar_chart(df_movies, 'Top 10 Genres - Movies'), use_container_width=True)
    st.plotly_chart(create_country_map(df_movies, 'Global Distribution of Movies'), use_container_width=True)
elif selection == 'TV Series':
    st.plotly_chart(create_treemap(df_tv_series, 'Parental Guide - TV Series'), use_container_width=True)
    st.plotly_chart(create_genre_bar_chart(df_tv_series, 'Top 10 Genres - TV Series'), use_container_width=True)
    st.plotly_chart(create_country_map(df_tv_series, 'Global Distribution of TV Series'), use_container_width=True)