As someone who often feels that they did not get enough sleep, I want to explore how the things that people do around their bedtime affect how well they sleep and how tired they feel the next day. I feel like many people (especially young adults) are always complaining about how tired they are and how reliant they have become on caffiene, so I want to find a way to change that. Many sources that I have read online including MedlinePlus and the CDC suggest that screens, such as the ones on our phones, are the main culprit for this issue, and I want to explore whether that is true. I also wanted to see whether having breakfast in the morning affected how tired someone felt because I usually find myself in a rush in the morning with no time to eat. My dataset is from Kaggle.
import pandas as pd
import csv
# opens the csv file
with open('SleepStudyData.csv', 'r') as file:
# stores the csv file as a dictionary
reader = csv.DictReader(file)
# create an empty dictionary to store the data
sleep_dict = {}
# iterates through each row of the data
for row in reader:
# iterates through each key-value pair in the row dictionary
for column, value in row.items():
# adds the value to a list for the corresponding column key in the data_dict dictionary
sleep_dict.setdefault(column, []).append(value)
# uses dictionary to create a dataframe
df_sleep = pd.DataFrame.from_dict(sleep_dict)
df_sleep
# Column Meanings:
# Enough - do they think that they got enough sleep?
# Hours - on average, how many hours of sleep do they get on weeknights
# PhoneReach - do they sleep with their phone within arms reach?
# PhoneTime - do they use their phone within 30 minutes of falling asleep?
# Tired - on a scale from 1 to 5 how tired do they feel throughout the day?
# Breakfast - do they typically eat breakfast?
Enough | Hours | PhoneReach | PhoneTime | Tired | Breakfast | |
---|---|---|---|---|---|---|
0 | Yes | 8 | Yes | Yes | 3 | Yes |
1 | No | 6 | Yes | Yes | 3 | No |
2 | Yes | 6 | Yes | Yes | 2 | Yes |
3 | No | 7 | Yes | Yes | 4 | No |
4 | No | 7 | Yes | Yes | 2 | Yes |
... | ... | ... | ... | ... | ... | ... |
99 | No | 7 | Yes | Yes | 2 | Yes |
100 | No | 7 | No | Yes | 3 | Yes |
101 | Yes | 8 | Yes | Yes | 3 | Yes |
102 | Yes | 7 | Yes | Yes | 2 | Yes |
103 | Yes | 6 | Yes | Yes | 3 | Yes |
104 rows × 6 columns
My plan is to make multiple color-coded histograms or bar graphs so that related variables such as "Hours" and "Enough" can be clearly compared.