Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7562247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:22:07+00:00 2026-05-30T13:22:07+00:00

i want to split a date list in hours and do operations like an

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:22:09+00:00Added an answer on May 30, 2026 at 1:22 pm

    This query can be performed in sqlite. To group by hour:

    def SQLQueryDaily(currency,start,end):
        sql = '''
            SELECT buy, AVG(sell)
            FROM {t}
            WHERE (datetime > ? AND datetime < ?)
            GROUP BY strftime('%Y-%m-%d %H',date)
            '''.format(t = currency)
        c.execute(sql, [start, end])
        for row in c:
            print (row)    
    

    To group by 15 minutes:

    sql = '''
        SELECT buy, AVG(sell)
        FROM {t}
        WHERE (datetime > ? AND datetime < ?)
        GROUP BY strftime('%s', date)/(15*60)
        '''.format(t = currency)
    

    To get the first and last row of each group:

    sql = '''
        SELECT f.date, f.sell, t.minp, t.maxp, t.avgp
        FROM {t} f
        INNER JOIN (
            SELECT MIN(date) mindate, MAX(date) maxdate,
                   MIN(sell) minp, MAX(sell) maxp, AVG(sell) avgp
            FROM {t}
            GROUP BY strftime('%s', date)/(15*60)
            ) t
            ON f.date = t.mindate or f.date = t.maxdate
        '''.format(t = currency)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to split a command line like string in single string parameters. How
I want to split a string like this: abc//def//ghi into a part before and
I want to call a PHP webservice from my J2ME program. Here is the
I have a string that has several date values in it, and I want
I want to split this string up into parts like Source: Web, Pics: 1
I want to split a semicolon separated string so that I can store each
I want split a string using PHP to get a individual date info. For
I want to split the string String fields = name[Employee Name], employeeno[Employee No], dob[Date
I want to create a multilne variable that will be split over several-lines, indenting
I want to split an arithmetic expression into tokens, to convert it into RPN.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.