import streamlit as st import pandas as pd import plotly.express as px import seaborn as sns import matplotlib.pyplot as plt st.title('Time Wasters on Social Media') df = pd.read_csv('Time-Wasters on Social Media.csv') st.subheader("Country-wise Addiction Levels by Demographics") col1,col2=st.columns(2) st.write("") st.markdown("
",unsafe_allow_html=True) st.write("") with col1: st.metric("Total Users",len(df['UserID'].unique().tolist())) with col2: st.metric("Total Time Spent", int(df['Total Time Spent'].sum())) selected_country = st.selectbox("Select Country", df['Location'].unique().tolist()) selected_gender = st.selectbox("Select Gender", df['Gender'].unique().tolist()) min_age, max_age = int(df['Age'].min()), int(df['Age'].max()) selected_age_range = st.slider("Select Age Range", min_age, max_age, (min_age, max_age)) selected_platform = st.selectbox("Select Platform", df['Platform'].unique().tolist()) filtered_data = df[ (df['Location'] == selected_country) & (df['Gender'] == selected_gender) & (df['Age'] >= selected_age_range[0]) & (df['Age'] <= selected_age_range[1]) & (df['Platform'] == selected_platform) ] # st.write(filtered_data) avg_addiction_level = filtered_data['Addiction Level'].mean() st.subheader(f"Average Addiction Level in {selected_country} for {selected_gender} users aged {selected_age_range[0]} to {selected_age_range[1]} on {selected_platform}:") st.write(f"*{avg_addiction_level:.2f}*") st.subheader("Addiction Level Distribution") plt.figure(figsize=(10, 6)) sns.histplot(data=filtered_data, x='Addiction Level', kde=True, bins=10, color='teal') plt.title(f"Addiction Level Distribution in {selected_country} for {selected_gender} users") plt.xlabel('Addiction Level') plt.ylabel('Frequency') st.pyplot(plt) #Time Spenditure Analysis # platform=st.multiselect("Select Platforms",df['Platform'].unique().tolist()) # filter1_df= df[ # (df['Platform'] == platform) & # (df['Frequency']) & # (df['Total Time Spent']) # ] # time_spent_on_platform=filter1_df[["Platform","Frequency","Total Time Spent"]].groupby(['Platform','Frequency']).sum().reset_index() # pivot_time_spent_on_platform = pd.pivot(time_spent_on_platform,index='Frequency',columns='Platform',values='Total Time Spent') # pivot_time_spent_on_platform.reset_index(inplace=True) # pivot_time_spent_on_platform.set_index("Frequency", inplace=True) # fig1,ax1=plt.subplots(figsize=(9, 7)) # ax1.plot(pivot_time_spent_on_platform,linestyle='--',marker='o') # plt.xlabel('Frequency') # plt.ylabel('Total Time Spent') # plt.title('Multiline Line Plot from Pivot Table') # plt.legend(df['Platform'],title='Platform',loc=2) # ax1.grid(True) # st.pyplot(fig1) # st.write("") # st.write("") # st.markdown("
",unsafe_allow_html=True) # st.write("") # st.write("") watch_reason_counts = filtered_data['Watch Reason'].value_counts() st.subheader("Most Common Watch Reasons") st.write(watch_reason_counts) st.subheader("Country-wise Engagement Levels") avg_engagement_by_country = df.groupby('Location')['Engagement'].mean().sort_values(ascending=False) st.bar_chart(avg_engagement_by_country) st.subheader("Addiction Level vs Age") selected_country = st.selectbox("Select Country", df['Location'].unique(), key='country_select_addiction') selected_platform = st.selectbox("Select Platform", df['Platform'].unique(), key='platform_select_addiction') filtered_data = df[(df['Location'] == selected_country) & (df['Platform'] == selected_platform)] plt.figure(figsize=(10, 6)) sns.lineplot(data=filtered_data, x='Age', y='Addiction Level', marker='o') plt.title(f'Addiction Level vs Age in {selected_country} on {selected_platform}') plt.xlabel('Age') plt.ylabel('Addiction Level') st.pyplot(plt) st.subheader("Engagement Levels by Platform") age_range = st.slider("Select Age Range", int(df['Age'].min()), int(df['Age'].max()), (20, 40), key='age_slider_platform') filtered_data = df[(df['Age'] >= age_range[0]) & (df['Age'] <= age_range[1])] plt.figure(figsize=(10, 6)) sns.boxplot(data=filtered_data, x='Platform', y='Engagement', palette='Set3') plt.title(f'Engagement Levels for Age Group {age_range[0]} to {age_range[1]}') st.pyplot(plt) st.subheader("Gender-wise Comparison of Productivity Loss") selected_platform = st.selectbox("Select Platform", df['Platform'].unique(), key='platform_select_prod_loss') filtered_data = df[df['Platform'] == selected_platform] gender_prod_loss = filtered_data.groupby('Gender')['ProductivityLoss'].mean() st.bar_chart(gender_prod_loss) st.subheader("Engagement vs Productivity Loss") plt.figure(figsize=(10, 6)) sns.scatterplot(data=df, x='Engagement', y='ProductivityLoss', hue='Platform', palette='viridis', s=100) plt.title('Engagement vs Productivity Loss across Platforms') st.pyplot(plt) st.subheader("Watch Reasons per Demographic") selected_country = st.selectbox("Select Country", df['Location'].unique(), key='country_select_watch_reason') age_range = st.slider("Select Age Range", int(df['Age'].min()), int(df['Age'].max()), (20, 40), key='age_slider_watch_reason') filtered_data = df[(df['Location'] == selected_country) & (df['Age'] >= age_range[0]) & (df['Age'] <= age_range[1])] watch_reasons = filtered_data['Watch Reason'].value_counts() st.bar_chart(watch_reasons) # import streamlit as st # import pandas as pd # import plotly.express as px # import seaborn as sns # import matplotlib.pyplot as plt # # Custom CSS for Stunning UI # st.markdown( # """ # # """, # unsafe_allow_html=True # ) # # Display Title # st.markdown("

Welcome to the Time-Wasters on Social Media Analytics

", unsafe_allow_html=True) # st.write("") # # Display Subtitle # st.markdown("

Dive into the insights of Social Media Engagement and Addiction.

", unsafe_allow_html=True) # st.write("") # # Content Section with Glassmorphism # st.markdown( # """ #
#

🔍 What You Will Discover:

#
    #
  1. Analysis of Users and their activity over Social Media
  2. #
  3. Engagement Levels of Users over Social Media
  4. #
  5. Addiction Levels of Users over Social Media
  6. #
#
# """, # unsafe_allow_html=True # ) # # Call-to-Action Button # if st.button(" Explore Dashboard "): # st.switch_page("dashboard.py") # Ensure 'dashboard.py' exists as the main dashboard page # # --- KEEPING PLOTTING AND FUNCTIONALITY UNTOUCHED BELOW --- # st.title('Time Wasters on Social Media') # df = pd.read_csv('Time-Wasters on Social Media.csv') # st.subheader("Country-wise Addiction Levels by Demographics") # col1, col2 = st.columns(2) # with col1: # st.metric("Total Users", len(df['UserID'].unique().tolist())) # with col2: # st.metric("Total Time Spent", int(df['Total Time Spent'].sum())) # selected_country = st.selectbox("Select Country", df['Location'].unique().tolist()) # selected_gender = st.selectbox("Select Gender", df['Gender'].unique().tolist()) # min_age, max_age = int(df['Age'].min()), int(df['Age'].max()) # selected_age_range = st.slider("Select Age Range", min_age, max_age, (min_age, max_age)) # selected_platform = st.selectbox("Select Platform", df['Platform'].unique().tolist()) # filtered_data = df[ # (df['Location'] == selected_country) & # (df['Gender'] == selected_gender) & # (df['Age'] >= selected_age_range[0]) & # (df['Age'] <= selected_age_range[1]) & # (df['Platform'] == selected_platform) # ] # avg_addiction_level = filtered_data['Addiction Level'].mean() # st.subheader(f"Average Addiction Level in {selected_country} for {selected_gender} users aged {selected_age_range[0]} to {selected_age_range[1]} on {selected_platform}:") # st.write(f"*{avg_addiction_level:.2f}*") # st.subheader("Addiction Level Distribution") # plt.figure(figsize=(10, 6)) # sns.histplot(data=filtered_data, x='Addiction Level', kde=True, bins=10, color='teal') # st.pyplot(plt) # watch_reason_counts = filtered_data['Watch Reason'].value_counts() # st.subheader("Most Common Watch Reasons") # st.write(watch_reason_counts) # st.subheader("Country-wise Engagement Levels") # avg_engagement_by_country = df.groupby('Location')['Engagement'].mean().sort_values(ascending=False) # st.bar_chart(avg_engagement_by_country) # st.subheader("Addiction Level vs Age") # selected_country = st.selectbox("Select Country", df['Location'].unique(), key='country_select_addiction') # selected_platform = st.selectbox("Select Platform", df['Platform'].unique(), key='platform_select_addiction') # filtered_data = df[(df['Location'] == selected_country) & (df['Platform'] == selected_platform)] # sns.lineplot(data=filtered_data, x='Age', y='Addiction Level', marker='o') # st.pyplot(plt) # import streamlit as st # import pandas as pd # import plotly.express as px # import seaborn as sns # import matplotlib.pyplot as plt # st.title('Time Wasters on Social Media') # df = pd.read_csv('Time-Wasters on Social Media.csv') # st.subheader("Country-wise Addiction Levels by Demographics") # col1,col2=st.columns(2) # st.write("") # st.markdown("
",unsafe_allow_html=True) # st.write("") # with col1: # st.metric("Total Users",len(df['UserID'].unique().tolist())) # with col2: # st.metric("Total Time Spent", int(df['Total Time Spent'].sum())) # selected_country = st.selectbox("Select Country", df['Location'].unique().tolist()) # selected_gender = st.selectbox("Select Gender", df['Gender'].unique().tolist()) # min_age, max_age = int(df['Age'].min()), int(df['Age'].max()) # selected_age_range = st.slider("Select Age Range", min_age, max_age, (min_age, max_age)) # selected_platform = st.selectbox("Select Platform", df['Platform'].unique().tolist()) # filtered_data = df[ # (df['Location'] == selected_country) & # (df['Gender'] == selected_gender) & # (df['Age'] >= selected_age_range[0]) & # (df['Age'] <= selected_age_range[1]) & # (df['Platform'] == selected_platform) # ] # # st.write(filtered_data) # avg_addiction_level = filtered_data['Addiction Level'].mean() # st.subheader(f"Average Addiction Level in {selected_country} for {selected_gender} users aged {selected_age_range[0]} to {selected_age_range[1]} on {selected_platform}:") # st.write(f"*{avg_addiction_level:.2f}*") # st.subheader("Addiction Level Distribution") # plt.figure(figsize=(10, 6)) # sns.histplot(data=filtered_data, x='Addiction Level', kde=True, bins=10, color='teal') # plt.title(f"Addiction Level Distribution in {selected_country} for {selected_gender} users") # plt.xlabel('Addiction Level') # plt.ylabel('Frequency') # st.pyplot(plt) # #Time Spenditure Analysis # # platform=st.multiselect("Select Platforms",df['Platform'].unique().tolist()) # # filter1_df= df[ # # (df['Platform'] == platform) & # # (df['Frequency']) & # # (df['Total Time Spent']) # # ] # # time_spent_on_platform=filter1_df[["Platform","Frequency","Total Time Spent"]].groupby(['Platform','Frequency']).sum().reset_index() # # pivot_time_spent_on_platform = pd.pivot(time_spent_on_platform,index='Frequency',columns='Platform',values='Total Time Spent') # # pivot_time_spent_on_platform.reset_index(inplace=True) # # pivot_time_spent_on_platform.set_index("Frequency", inplace=True) # # fig1,ax1=plt.subplots(figsize=(9, 7)) # # ax1.plot(pivot_time_spent_on_platform,linestyle='--',marker='o') # # plt.xlabel('Frequency') # # plt.ylabel('Total Time Spent') # # plt.title('Multiline Line Plot from Pivot Table') # # plt.legend(df['Platform'],title='Platform',loc=2) # # ax1.grid(True) # # st.pyplot(fig1) # # st.write("") # # st.write("") # # st.markdown("
",unsafe_allow_html=True) # # st.write("") # # st.write("") # watch_reason_counts = filtered_data['Watch Reason'].value_counts() # st.subheader("Most Common Watch Reasons") # st.write(watch_reason_counts) # st.subheader("Country-wise Engagement Levels") # avg_engagement_by_country = df.groupby('Location')['Engagement'].mean().sort_values(ascending=False) # st.bar_chart(avg_engagement_by_country) # st.subheader("Addiction Level vs Age") # selected_country = st.selectbox("Select Country", df['Location'].unique(), key='country_select_addiction') # selected_platform = st.selectbox("Select Platform", df['Platform'].unique(), key='platform_select_addiction') # filtered_data = df[(df['Location'] == selected_country) & (df['Platform'] == selected_platform)] # plt.figure(figsize=(10, 6)) # sns.lineplot(data=filtered_data, x='Age', y='Addiction Level', marker='o') # plt.title(f'Addiction Level vs Age in {selected_country} on {selected_platform}') # plt.xlabel('Age') # plt.ylabel('Addiction Level') # st.pyplot(plt) # st.subheader("Engagement Levels by Platform") # age_range = st.slider("Select Age Range", int(df['Age'].min()), int(df['Age'].max()), (20, 40), key='age_slider_platform') # filtered_data = df[(df['Age'] >= age_range[0]) & (df['Age'] <= age_range[1])] # plt.figure(figsize=(10, 6)) # sns.boxplot(data=filtered_data, x='Platform', y='Engagement', palette='Set3') # plt.title(f'Engagement Levels for Age Group {age_range[0]} to {age_range[1]}') # st.pyplot(plt) # st.subheader("Gender-wise Comparison of Productivity Loss") # selected_platform = st.selectbox("Select Platform", df['Platform'].unique(), key='platform_select_prod_loss') # filtered_data = df[df['Platform'] == selected_platform] # gender_prod_loss = filtered_data.groupby('Gender')['ProductivityLoss'].mean() # st.bar_chart(gender_prod_loss) # st.subheader("Engagement vs Productivity Loss") # plt.figure(figsize=(10, 6)) # sns.scatterplot(data=df, x='Engagement', y='ProductivityLoss', hue='Platform', palette='viridis', s=100) # plt.title('Engagement vs Productivity Loss across Platforms') # st.pyplot(plt) # st.subheader("Watch Reasons per Demographic") # selected_country = st.selectbox("Select Country", df['Location'].unique(), key='country_select_watch_reason') # age_range = st.slider("Select Age Range", int(df['Age'].min()), int(df['Age'].max()), (20, 40), key='age_slider_watch_reason') # filtered_data = df[(df['Location'] == selected_country) & (df['Age'] >= age_range[0]) & (df['Age'] <= age_range[1])] watch_reasons = filtered_data['Watch Reason'].value_counts() # st.bar_chart(watch_reasons)