Skip to content

Instantly share code, notes, and snippets.

@mohataher
Created January 24, 2018 16:51
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mohataher/8bfbc81066ddd2bc4bf9f928f10817ad to your computer and use it in GitHub Desktop.
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