I am trying the following:
import pyodbc
from datetime import timedelta
import pandas as pd
query = "SELECT dateCol, hourCol, loadCol FROM myTable"
cursor = conn.cursor()
cursor.execute(query)
zload = pd.DataFrame({'DateTime':[], 'Load':[]})
for row in cursor:
dateTime = pd.to_datetime(row[0], format='%Y-%m-%d') + td(hours=int(row[1]))
load = float(row[2])
zload.append({dateTime: load})
I am not able to get the following line of code right: zload.append({dateTime: load})
I am trying to create a dataframe with datatime as index and load as value.
A sample row looks as: row
(u'2002-01-01', '1 ', Decimal('8331.46'))
where row[0] is date; row[1] is hour and row[2] is load
Or is there an alternate way to achieve the above where I read the table from database and create pandas dataframe out of it using logic above.