Your client, SleepInc, has shared anonymized sleep data from their hot new sleep tracking app SleepScope. As their data science consultant, your mission is to analyze the lifestyle survey data with Python to discover relationships between exercise, gender, occupation, and sleep quality. See if you can identify patterns leading to insights on sleep quality.
💾 The data: sleep_health_data.csv
SleepInc has provided you with an anonymized dataset of sleep and lifestyle metrics for 374 individuals. This dataset contains average values for each person calculated over the past six months. The data is saved as sleep_health_data.csv
.
The dataset includes 13 columns covering sleep duration, quality, disorders, exercise, stress, diet, demographics, and other factors related to sleep health.
Column | Description |
---|---|
Person ID | An identifier for each individual. |
Gender | The gender of the person (Male/Female). |
Age | The age of the person in years. |
Occupation | The occupation or profession of the person. |
Sleep Duration (hours) | The average number of hours the person sleeps per day. |
Quality of Sleep (scale: 1-10) | A subjective rating of the quality of sleep, ranging from 1 to 10. |
Physical Activity Level (minutes/day) | The average number of minutes the person engages in physical activity daily. |
Stress Level (scale: 1-10) | A subjective rating of the stress level experienced by the person, ranging from 1 to 10. |
BMI Category | The BMI category of the person (e.g., Underweight, Normal, Overweight). |
Blood Pressure (systolic/diastolic) | The average blood pressure measurement of the person, indicated as systolic pressure over diastolic pressure. |
Heart Rate (bpm) | The average resting heart rate of the person in beats per minute. |
Daily Steps | The average number of steps the person takes per day. |
Sleep Disorder | The presence or absence of a sleep disorder in the person (None, Insomnia, Sleep Apnea). |
import pandas as pd
sleep_df = pd.read_csv("sleep_health_data.csv")
sleep_df.head(10)
1. Which occupation has the lowest average sleep duration?
- The Sales Representative occupation has the lowest average sleep duration
lowest_sleep_occ = sleep_df.groupby('Occupation')['Sleep Duration'].agg(func=['mean']).round(2).index[6]
print(lowest_sleep_occ)
2. Which occupation has the lowest average sleep quality?
- The Sales Representative occupation has the lowest average sleep quality, which also happens to have the lowest sleep duration.
lowest_sleep_quality_occ = sleep_df.groupby('Occupation')['Quality of Sleep'].agg(func=['mean']).round(2).index[6]
print(lowest_sleep_quality_occ)
same_occ = True
same_occ
3. Explore how BMI category affects sleep disorder rates
- Find ratio of app users were diagnosed with insomnia
- Create a dictionary that stores the ratios of insomnia users called
bmi_insomnia_ratios
The distribution ratios of users with insomnia for each BMI category is shown below:
BMI Category | Ratio |
---|---|
Normal | 0.04 |
Overweight | 0.43 |
Obese | 0.40 |
# find total bmi ratios of the sleep_df
total_bmi_category_ratios = sleep_df['BMI Category'].value_counts()
# find subset of users with insomnia
bmi_insomnia_df = sleep_df[sleep_df['Sleep Disorder'] == 'Insomnia']
# find total bmi ratios of users with insomnia
total_bmi_insomnia_ratios = bmi_insomnia_df['BMI Category'].value_counts()
# calculate the ratio of users with insomnia for each BMI category and store results in a dictionary
bmi_insomnia_ratios_series = round((total_bmi_insomnia_ratios/total_bmi_category_ratios), 2)
bmi_insomnia_ratios = {"Normal": 0.04, "Overweight": 0.43, "Obese": 0.40}
bmi_insomnia_ratios
1 hidden cell