import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
Load the data
df = pd.read_csv('data.csv')
Data Cleaning: Renaming columns for easier access
column_names = {
'1. What is your age?': 'Age',
'2. Gender': 'Gender',
'3. Relationship Status': 'Relationship_Status',
'4. Occupation Status': 'Occupation_Status',
'5. What type of organizations are you affiliated with?': 'Affiliated_Organizations',
'6. Do you use social media?': 'Uses_Social_Media',
'7. What social media platforms do you commonly use?': 'Common_Social_Media',
'8. What is the average time you spend on social media every day?': 'Avg_Time_Spend_On_Social_Media',
'9. How often do you find yourself using Social media without a specific purpose?': 'Social_Media_Usage_Purpose',
'10. How often do you get distracted by Social media when you are busy doing something?': 'Social_Media_Distraction_Frequency',
'11. Do you feel restless if you haven't used Social media in a while?': 'Restlessness_Due_to_Social_Media',
'12. On a scale of 1 to 5, how easily distracted are you?': 'Distractibility_Score',
'13. On a scale of 1 to 5, how much are you bothered by worries?': 'Worry_Level',
'14. Do you find it difficult to concentrate on things?': 'Concentration_Difficulty',
'15. On a scale of 1-5, how often do you compare yourself to other successful people through the use of social media?': 'Comparison_Frequency',
'16. Following the previous question, how do you feel about these comparisons, generally speaking?': 'Comparison_Feelings',
'17. How often do you look to seek validation from features of social media?': 'Validation_Seeking_Frequency',
'18. How often do you feel depressed or down?': 'Depression_Frequency',
'19. On a scale of 1 to 5, how frequently does your interest in daily activities fluctuate?': 'Interest_Fluctuation_Frequency',
'20. On a scale of 1 to 5, how often do you face issues regarding sleep?': 'Sleep_Issue_Frequency'
}
df.rename(columns=column_names, inplace=True)
Data Cleaning: Converting categorical ‘average time spend on social media’ into numerical format
time_mapping = {
'Less than an Hour': 0.5, # Assuming ‘Less than an Hour’ to be half an hour for simplicity
'Between 2 and 3 hours': 2.5,
'Between 3 and 4 hours': 3.5,
'More than 5 hours': 5.5, # Since it’s more than 5 hours, assuming 5.5 for simplicity
# Add other mappings as needed…
}
df['Avg_Time_Spend_On_Social_Media_Hours'] = df['Avg_Time_Spend_On_Social_Media'].map(time_mapping)
Feature Engineering: Counting number of social media platforms used
df['Num_Social_Media_Platforms'] = df['Common_Social_Media'].apply(lambda x: len(x.split(', ')))
Feature Engineering: Create a feature that is a summation of all scale-based responses (12-20)
scale_questions = [col for col in df if col.startswith('12.') or col.startswith('19.') or col.startswith('20.')]
df['Scale_Questions_Sum'] = df[scale_questions].sum(axis=1)
Convert Timestamp to datetime and extract useful features like the day of the week and hour of the day
df['Timestamp'] = pd.to_datetime(df['Timestamp'])
df['Day_of_Week'] = df['Timestamp'].dt.day_name()
df['Hour_of_Day'] = df['Timestamp'].dt.hour
Basic Exploratory Analysis
print(df.describe()) # Basic descriptive statistics
print(df.corr()) # Correlation matrix
Advanced Analysis:
1. Regression Analysis:
Perform linear regression to predict the Scale_Questions_Sum (mental well-being score) based on other features.
2. Subgroup Analysis:
Divide the data into subgroups based on age, gender, or social media usage patterns and analyze each subgroup separately.
3. Time Series Analysis:
If the dataset includes a time component, perform time series analysis to examine trends and patterns over time.
4. Sentiment Analysis:
If the dataset includes open-ended responses, perform sentiment analysis to gauge the overall sentiment expressed in these responses.
5. Machine Learning Models:
Train and evaluate machine learning models, such as decision trees or random forests, to predict mental well-being scores based on various features.
6. Natural Language Processing:
If the dataset includes textual data, apply natural language processing techniques to extract meaningful insights from the text.
7. Network Analysis:
If the dataset includes information about social connections, perform network analysis to examine the relationships between individuals and how they influence social media usage and mental well-being.
Now create visualizations:
1. Correlation Heatmap:
Create a correlation heatmap to visualize the relationships between different variables.
2. Scatter Plots:
Create scatter plots to examine the relationships between pairs of variables, such as age and mental well-being score.
3. Bar Charts:
Create bar charts to compare the distribution of mental well-being scores across different subgroups, such as age groups or genders.
4. Time Series Plots:
Create time series plots to visualize trends in mental well-being scores over time.
5. Word Clouds:
Create word clouds to visualize the most frequently occurring words in open-ended responses.
6. Network Visualization:
Create network visualizations to represent the relationships between individuals and how they influence social media usage and mental well-being.
Conclusion:
Summarize the key findings and insights gained from the analysis, and discuss the implications for understanding the relationship between social media usage and mental well-being.