Movie_dashboard / app.py
Penguni's picture
Update app.py
dd67cb4 verified
raw
history blame
2.68 kB
import streamlit as st
import pandas as pd
import plotly.express as px
# 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_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']
fig = px.choropleth(locations=country_counts['country'], locationmode='country names',
color=country_counts['count'], hover_name=country_counts['country'],
title=title, color_continuous_scale=px.colors.sequential.Plasma)
fig.update_layout(showlegend=False)
return fig
def create_country_map(df, title):
country_counts = df['country'].value_counts().reset_index()
country_counts.columns = ['country', 'count']
fig = px.choropleth(country_counts, locations="country", locationmode='country names',
color="count", hover_name="country",
color_continuous_scale=px.colors.sequential.Plasma, title=title)
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)