Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A little function to extract heart rates with absolute timestamps from Polar CSV files
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