Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Help Grouping by Intervals on list
I am looking for a way to group a list of numbers into group of intervals and a count.

For example:

List = [1, 2, 3, 3.5, 3.6, 4, 5, 6, 7, 8, 9, 10, 14]
Interval = 2

To give the result of;

NewList = [1, 3, 5, 7, 9, 11, 13] #This will form the values in x scale of a graph
Counted_items = [2, 4, 2, 2, 2, 0, 1] #This will form the y axis as a count of each within that interval.

(2 = because there this is the count of the numbers between 1 and 3 within the list. 4 is returned because there are 4 numbers between 3 and the next number 5 in the list. Hoping that makes sense.

The result doesn't necessary be in the above format, i'm just looking to count numbers that exist based on a given interval in order to input later into a graph.

I am thinking I need to get the min number from the NewList and add the interval of 2 to this, keep looping over the values until the number is less than the next interval of 3. Output this to a new list. Seem to having difficulty on how to tackle this one. Going between a defined function or either using intertools or even pandas. Be grateful if someone can point me in the right direction.
I don't know if it can be of use to you, but if I'm right:

interval = abs(list[1] - list[2])

if interval == required_interval:
Loop this with the index numbers + 1 each time and I think you can work along the list like that.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Grouping a list of various time into intervals paul41 1 101 Nov-24-2019, 01:47 PM
Last Post: buran
  resample grouping pr0blem olufemig 1 76 Nov-06-2019, 10:45 PM
Last Post: Larz60+
  Splitting lines ang grouping three at once samsonite 5 300 Jun-21-2019, 05:19 PM
Last Post: ichabod801
  Grouping csv by name terrydidi 8 531 Jan-14-2019, 09:27 AM
Last Post: perfringo
  Function for grouping variables Scott 1 548 Nov-13-2018, 03:01 AM
Last Post: ichabod801
  Python grouping program GhostZero199 2 1,287 Jul-18-2017, 12:44 PM
Last Post: sparkz_alot

Forum Jump:

Users browsing this thread: 1 Guest(s)