i want to split a date list in hours and do operations like an average.
I’ve written a python program that call a sqlite3 database, the query returns a list:
def SQLQueryDaily(currency,start,end):
#year = start[0,3]
c.execute('SELECT buy, sell FROM '+currency+' WHERE (datetime > "'+start+'" AND datetime < "'+end+'")')
for row in c:
print (row)
and it prints:
(‘2002-01-02 01:33:57’, 0.894)
(‘2002-01-02 01:33:58’, 0.895)
(‘2002-01-02 01:33:59’, 0.893)
and so on for thousands of lines…
what i want to do is to regroup this list into hours and do the average in the number returned (here : 0.894)
I honestly tried to find a way to regroup results by hour or days but i don’t know if there is a proper way to do it, please help thanks
This query can be performed in sqlite. To group by hour:
To group by 15 minutes:
To get the first and last row of each group: