Created
January 24, 2018 16:51
-
-
Save mohataher/8bfbc81066ddd2bc4bf9f928f10817ad to your computer and use it in GitHub Desktop.
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
import pandas as pd | |
import datetime | |
import time | |
row=None | |
with open("hr.csv") as fp: | |
for i, line in enumerate(fp): | |
if i == 1: | |
print(line) | |
row=line | |
elif i > 1: | |
break | |
splits=row.split(',') | |
print(splits) | |
date=splits[2] | |
mtime=splits[3] | |
mdatetime = date+' '+mtime | |
starting_ts = pd.to_datetime(mdatetime) | |
dates=[] | |
hrs=[] | |
with open("data/hr.csv") as fp: | |
for i, line in enumerate(fp): | |
if i < 3: | |
continue #skip headers | |
else: | |
splits=line.split(',') | |
rate=splits[1] | |
hr=splits[2] | |
#print(hr) | |
x = time.strptime(rate.split(',')[0],'%H:%M:%S') | |
seconds = datetime.timedelta(hours=x.tm_hour,minutes=x.tm_min,seconds=x.tm_sec).total_seconds() | |
#print(seconds) | |
ndate= starting_ts + pd.to_timedelta(seconds, unit='s') | |
#print(ndate) | |
dates.append(ndate) | |
hrs.append(hr) | |
data={'date':dates, 'hr':hrs} | |
df = pd.DataFrame(data=data, index=dates) | |
df.head() | |
df.to_csv('hr_df.csv') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment