Quick statistical summary

With the pandas groupby() and describe() methods one can generate a statistical summary for several populations in a dataset with very little effort.

In [1]:
import pandas as pd

# Import data
df = pd.read_csv('Smartphone_Usage_Productivity_Dataset_50000.csv')

# Check what columns we have to work with
print(df.columns)
Index(['User_ID', 'Age', 'Gender', 'Occupation', 'Device_Type',
       'Daily_Phone_Hours', 'Social_Media_Hours', 'Work_Productivity_Score',
       'Sleep_Hours', 'Stress_Level', 'App_Usage_Count',
       'Caffeine_Intake_Cups', 'Weekend_Screen_Time_Hours'],
      dtype='str')

Group data by Gender and Occupation and apply .describe() to the Daily_Phone_Hours column. We can keep it tidy by rounding the numbers.

In [2]:
# Group data and apply .describe()
df = df.groupby(['Gender', 'Occupation'])['Daily_Phone_Hours'].describe()

# Round numbers
df = df.round(2)

print(df)
                        count  mean   std  min  25%  50%  75%   max
Gender Occupation                                                  
Female Business Owner  4169.0  6.54  3.14  1.0  3.9  6.6  9.2  12.0
       Freelancer      4217.0  6.52  3.17  1.0  3.8  6.5  9.2  12.0
       Professional    4151.0  6.50  3.16  1.0  3.8  6.5  9.2  12.0
       Student         4142.0  6.49  3.15  1.0  3.8  6.5  9.2  12.0
Male   Business Owner  4139.0  6.58  3.16  1.0  3.9  6.6  9.3  12.0
       Freelancer      4046.0  6.53  3.18  1.0  3.8  6.6  9.3  12.0
       Professional    4265.0  6.50  3.15  1.0  3.8  6.5  9.2  12.0
       Student         4258.0  6.48  3.20  1.0  3.7  6.4  9.2  12.0
Other  Business Owner  4151.0  6.51  3.16  1.0  3.8  6.5  9.2  12.0
       Freelancer      4132.0  6.49  3.19  1.0  3.7  6.4  9.3  12.0
       Professional    4213.0  6.47  3.20  1.0  3.6  6.5  9.2  12.0
       Student         4117.0  6.51  3.19  1.0  3.7  6.6  9.3  12.0

This tutorial uses the "Screen Time, Sleep & Stress Analysis Dataset" available on Kaggle under the CC0: Public Domain license.

source: https://www.kaggle.com/datasets/amar5693/screen-time-sleep-and-stress-analysis-dataset