Python Forum
Help Grouping by Intervals on list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Grouping by Intervals on list
#1
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.
Reply


Messages In This Thread
Help Grouping by Intervals on list - by paul41 - Dec-03-2019, 07:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Grouping Data based on 30% bracket purnima1 4 1,196 Mar-10-2023, 07:38 PM
Last Post: deanhystad
  Grouping and sum of a list of objects Otbredbaron 1 3,217 Oct-23-2021, 01:42 PM
Last Post: Gribouillis
  time intervals project_science 7 2,966 Feb-06-2021, 11:49 PM
Last Post: project_science
  Plotting “simple” diagram with gridlines at specified intervals schniefen 1 2,424 Dec-03-2020, 05:54 PM
Last Post: schniefen
  Grouping and summing of dataset jef 0 1,645 Oct-04-2020, 11:03 PM
Last Post: jef
  Setting Tick Intervals In Sub Plots JoeDainton123 1 1,805 Oct-03-2020, 11:52 PM
Last Post: scidam
  Grouping algorithm riccardoob 7 3,033 May-19-2020, 01:22 PM
Last Post: deanhystad
  Grouping a list of various time into intervals paul41 1 3,785 Nov-24-2019, 01:47 PM
Last Post: buran
  resample grouping pr0blem olufemig 1 1,962 Nov-06-2019, 10:45 PM
Last Post: Larz60+
  Splitting lines ang grouping three at once samsonite 5 2,766 Jun-21-2019, 05:19 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020