| 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("<hr>",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("<hr>",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( | |
| # """ | |
| # <style> | |
| # /* Background Gradient */ | |
| # body { | |
| # background: linear-gradient(to right, #0f2027, #203a43, #2c5364); | |
| # color: white; | |
| # } | |
| # /* Main Title Styling */ | |
| # .main-title { | |
| # text-align: center; | |
| # color: #ffffff; | |
| # font-size: 60px; | |
| # font-weight: bold; | |
| # text-shadow: 3px 3px 15px rgba(255,255,255,0.3); | |
| # } | |
| # /* Subtitle Styling */ | |
| # .subtitle { | |
| # text-align: center; | |
| # color: #d1d1d1; | |
| # font-size: 38px; | |
| # font-style: italic; | |
| # } | |
| # /* Glassmorphism Card Effect */ | |
| # .content-box { | |
| # background: rgba(255, 255, 255, 0.15); | |
| # padding: 25px; | |
| # border-radius: 20px; | |
| # backdrop-filter: blur(12px); | |
| # box-shadow: 4px 6px 15px rgba(0,0,0,0.2); | |
| # margin: 25px; | |
| # } | |
| # /* List Styling */ | |
| # .list-item { | |
| # color: #FFD700; | |
| # font-size: 28px; | |
| # padding: 8px; | |
| # transition: transform 0.3s, color 0.3s; | |
| # } | |
| # .list-item:hover { | |
| # color: #FF4500; | |
| # transform: scale(1.08); | |
| # } | |
| # /* Stylish Buttons */ | |
| # .stButton>button { | |
| # background: linear-gradient(to right, #ff7e5f, #feb47b); | |
| # color: white; | |
| # font-size: 20px; | |
| # border-radius: 10px; | |
| # padding: 14px 22px; | |
| # transition: all 0.3s ease-in-out; | |
| # border: none; | |
| # } | |
| # .stButton>button:hover { | |
| # background: linear-gradient(to right, #feb47b, #ff7e5f); | |
| # transform: scale(1.12); | |
| # } | |
| # </style> | |
| # """, | |
| # unsafe_allow_html=True | |
| # ) | |
| # # Display Title | |
| # st.markdown("<h1 class='main-title'> Welcome to the Time-Wasters on Social Media Analytics</h1>", unsafe_allow_html=True) | |
| # st.write("") | |
| # # Display Subtitle | |
| # st.markdown("<h3 class='subtitle'> Dive into the insights of Social Media Engagement and Addiction.</h3>", unsafe_allow_html=True) | |
| # st.write("") | |
| # # Content Section with Glassmorphism | |
| # st.markdown( | |
| # """ | |
| # <div class='content-box'> | |
| # <h4 style='color: #ffffff; font-size: 40px;'>🔍 What You Will Discover:</h4> | |
| # <ol> | |
| # <li class='list-item'> Analysis of Users and their activity over Social Media</li> | |
| # <li class='list-item'> Engagement Levels of Users over Social Media</li> | |
| # <li class='list-item'> Addiction Levels of Users over Social Media</li> | |
| # </ol> | |
| # </div> | |
| # """, | |
| # 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("<hr>",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("<hr>",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) |