-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_steps.py
35 lines (22 loc) · 993 Bytes
/
get_steps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import warnings
warnings.filterwarnings('ignore')
import pandas as pd
""" script to get steps data wanted from the all_records.csv file created in import_clean"""
all = pd.read_csv("apple_health_export/all_records.csv")
## get steps
steps_df = all[all['type'] == 'HKQuantityTypeIdentifierStepCount']
# convert dates to datetime
for date in ['creationDate', 'startDate', 'endDate']:
steps_df[date] = pd.to_datetime(steps_df[date])
# make step counts numeric
steps_df.loc[:, 'value'] = pd.to_numeric(steps_df.loc[:, 'value'])
# only want apple watch data
steps_df = steps_df[steps_df['sourceName'] == 'Rebecca’s Apple\xa0Watch']
# drop unnecessary columns (all rows, columns 1-8)
steps_df = steps_df.iloc[:, 1:9]
# group steps by date
# steps_date = steps_df.groupby(['creationDate']).sum()
# convert/string replace for easier naming
steps_df['type'] = steps_df['type'].str.replace('HKQuantityTypeIdentifier', '')
# write to csv
steps_df.to_csv("data/steps.csv", index=False)