Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.