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

  • Home
  • SEARCH
  • 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 646579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:37:39+00:00 2026-05-13T21:37:39+00:00

I have a large data loaded from a pickled file. The data is a

  • 0

I have a large data loaded from a pickled file. The data is a sorted list of tuples containing a datetime and an int like this

[ (datetime.datetime(2010, 2, 26, 12, 8, 17), 5594813L), 
  (datetime.datetime(2010, 2, 26, 12, 7, 31), 5594810L), 
  (datetime.datetime(2010, 2, 26, 12, 6, 4) , 5594807L),
  etc
]

I want to get a population density based on some time intervals. For example, I want to grab the number of records within 5 minute / 1 minute / 30 second periods.

What is the best method to do this? I know I can just loop through every instance in the list but was looking for a better approach (if one exists).

Desired output would be something like:

2010-01-01 04:10:00  --- 5000
2010-02-04 10:05:00  --- 4000
2010-01-02 13:25:00  --- 3999
  • 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-13T21:37:39+00:00Added an answer on May 13, 2026 at 9:37 pm

    bisect.bisect is another way to solve this problem:

    import datetime
    import bisect
    import collections
    
    data=[ (datetime.datetime(2010, 2, 26, 12, 8, 17), 5594813L), 
      (datetime.datetime(2010, 2, 26, 12, 7, 31), 5594810L), 
      (datetime.datetime(2010, 2, 26, 12, 6, 4) , 5594807L),
    ]
    interval=datetime.timedelta(minutes=1,seconds=30)
    start=datetime.datetime(2010, 2, 26, 12, 6, 4)
    grid=[start+n*interval for n in range(10)]
    bins=collections.defaultdict(list)
    for date,num in data:
        idx=bisect.bisect(grid,date)
        bins[idx].append(num)
    for idx,nums in bins.iteritems():
        print('{0} --- {1}'.format(grid[idx],len(nums)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a large list of static data from a server that i load
I have a large collection of data in an excel file (and csv files).
I have a rather large list of data that contains 5 properties per element.
I have large data sets (10 Hz data, so 864k points per 24 Hours)
We have some very large data files (5 gig to 1TB) where we need
I have a large amount of data I need to store, and be able
I have a large set of data (a data cube of 250,000 X 1,000
I have a large database of normalized order data that is becoming very slow
I have a large quantity of clearcase data which needs to be migrated into
I have a simulation that reads large binary data files that we create (10s

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.