Created
March 2, 2018 11:29
-
-
Save mgbckr/ce942044a35dd828be36073ff997e75d to your computer and use it in GitHub Desktop.
A little function to extract heart rates with absolute timestamps from Polar CSV files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_hr_from_polar_csv(filename): | |
# read header and data | |
h = pd.read_csv(filename, nrows=2) | |
d = pd.read_csv(filename, skiprows=2) | |
# parse start time | |
datetime_string = h["Date"].values[0] + " " + h["Start time"].values[0] | |
starttime = datetime.strptime(datetime_string, '%d-%m-%Y %H:%M:%S') | |
# function for parsing time deltas in data | |
def parse_timedelta_simple(string): | |
parsed = [int(t) for t in string.split(":")] | |
return timedelta(hours=parsed[0], minutes=parsed[1], seconds=parsed[2]) | |
parse_timedelta = np.vectorize(parse_timedelta_simple) | |
# calculate absolute time | |
d["Absolute time"] = starttime + parse_timedelta(d["Time"]) | |
# return absolute time and hr | |
return d["Absolute time"], d["HR (bpm)"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment