text_html_output_1.png
import datetime as dt

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

daily_activities = pd.read_csv('../input/fitbit/Fitabase Data 4.12.16-5.12.16/dailyActivity_merged.csv')
daily_calories = pd.read_csv('../input/fitbit/Fitabase Data 4.12.16-5.12.16/dailyCalories_merged.csv')
daily_intensities = pd.read_csv('../input/fitbit/Fitabase Data 4.12.16-5.12.16/dailyIntensities_merged.csv')
daily_steps = pd.read_csv('../input/fitbit/Fitabase Data 4.12.16-5.12.16/dailySteps_merged.csv')
hourly_steps = pd.read_csv('../input/fitbit/Fitabase Data 4.12.16-5.12.16/hourlySteps_merged.csv')
hourly_intensities = pd.read_csv('../input/fitbit/Fitabase Data 4.12.16-5.12.16/hourlyIntensities_merged.csv')
sleep_day = pd.read_csv('../input/fitbit/Fitabase Data 4.12.16-5.12.16/sleepDay_merged.csv')
weight_index = pd.read_csv('../input/fitbit/Fitabase Data 4.12.16-5.12.16/weightLogInfo_merged.csv')

len(weight_index.Id.unique())

len(daily_activities.Id.unique())

len(sleep_day.Id.unique())

sleep_day.columns = ['Id', 'Date', 'TotalSleepRecords', 'TotalMinutesAsleep', 'TotalTimeInBed']
daily_activities.columns = ['Id', 'Date', 'TotalSteps', 'TotalDistance', 'TrackerDistance', 'LoggedActivitiesDistance', 'VeryActiveDistance', 'ModeratelyActiveDistance', 'LightActiveDistance', 'SedentaryActiveDistance', 'VeryActiveMinutes', 'FairlyActiveMinutes', 'LightlyActiveMinutes', 'SedentaryMinutes', 'Calories']

sleep_day.Date = pd.to_datetime(sleep_day['Date'], format='%m/%d/%Y %I:%M:%S %p').dt.strftime('%m/%d/%Y')
daily_activities.Date = pd.to_datetime(daily_activities['Date'], format='%m/%d/%Y').dt.strftime('%m/%d/%Y')
weight_index.Date = pd.to_datetime(weight_index['Date'], format='%m/%d/%Y %I:%M:%S %p').dt.strftime('%m/%d/%Y')

#Change date into day of week
index_day=[]
week_day=[]
for i in range(len(daily_activities.Id)):
    day=dt.datetime.strptime(daily_activities.Date[i], "%m/%d/%Y")
    week_day.append(day.strftime("%A"))
    index_day.append(day.weekday())
    i=i+1
daily_activities["DayofWeek"]=week_day
daily_activities["IndexofWeek"]=index_day
gb_daily_activities=daily_activities.groupby(by=['DayofWeek']).mean().reset_index()
gb_daily_activities.sort_values("IndexofWeek")
sns.set_theme(style="darkgrid")
plt.figure(figsize=(10,8))
ax=sns.barplot(x="DayofWeek", y="TotalSteps",data=gb_daily_activities.sort_values("IndexofWeek"), palette="Accent_r")
ax.set_ylabel("Average Steps",fontsize=20)
ax.set_xlabel("Day of Week ",fontsize=20)
ax.set_title("Average Steps During Week ",fontsize=25)
plt.show()

hour = []
for i in range(len(hourly_steps.Id)):
    day = dt.datetime.strptime(hourly_steps.ActivityHour[i], '%m/%d/%Y  %I:%M:%S %p')
    hour.append(day.strftime('%H'))
    i = i + 1
hourly_steps['Hour'] = hour
gb_hourly_steps = hourly_steps.groupby('Hour').mean().reset_index()
sns.set_theme(style='darkgrid')
plt.figure(figsize=(10, 8))
hourly_chart = sns.barplot(data=gb_hourly_steps, x='Hour', y='StepTotal')
hourly_chart.set_ylabel('Average Steps', fontsize=20)
hourly_chart.set_xlabel('Hour', fontsize=20)
hourly_chart.set_title('Hourly distribution of user steps', fontsize=25)
plt.show()