I would like to create an array or list from values pulled from a SQL query. From research I believe the data I pull from SQL is a tuple.
How do format the data into a list I can use in python?
In my current code I try to use the numpy command np.asarray. I'm not sure if numpy arrays allow datetime.
import numpy as np
import pyodbc
conn = pyodbc.connect('login')
cursor = conn.cursor()
cursor.execute("SELECT PTIME, PVALUE FROM HISTORY_TABLE WHERE POINT = 'Value' AND PTIME> '2017-04-12' AND PTIME<'2017-04-13' AND HISTTYPE='AVG' AND PERIOD=7200")
sample = cursor.fetchall()
rockin = np.asarray(sample)
print rockin
cursor.close()
conn.close()
My result looks like this:
[[datetime.datetime(2017, 4, 12, 0, 0) 232.83]
[datetime.datetime(2017, 4, 12, 2, 0) 131.49]
[datetime.datetime(2017, 4, 12, 4, 0) 36.67]
...,
[datetime.datetime(2017, 4, 12, 18, 0) 82.08]
[datetime.datetime(2017, 4, 12, 20, 0) 368.83]
[datetime.datetime(2017, 4, 12, 22, 0) 435.79]]