Python Forum
Data binning help please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data binning help please
#1
Hi there, I have a homework where I need to create data bins using a dictionary. The instructions are:

Complete the specification of the bin_data function.

  • bin_data(data, binsize) should take a list of floats (stored in the variable data) and a float (stored in the variable binsize) and output a dictionary representing the binned data.
  • The output of the function is a dictionary whose keys represent the bins and whose values are ints indicating the number of data items in each bin.
  • The bins should start from the smallest value in data and increase in multiples of binsize. So, if the smallest value in the dataset was 0.0 and the binsize was 5.0 then the bins would represent the ranges 0.0 - 5.0; 5.0 - 10.0; 10.0 - 15.0; etc. There should be no bins above the largest value in data. All bins between the smallest and largest values should be included - if they do not contain any data items, then they should have a count of 0.
  • Bin ranges should be considered inclusive of their minimum value, and exclusive of their maximum. So 4.99 should be placed in the bin corresponding to the range 0.0 - 5.0, but 5.0 should be placed in the bin corresponding to the range 5.0 - 10.0.

This is what I have so far:

def bin_data(data, binsize):
    bins = {}
    data.sort()
    minBinSize = data[0]
    maxBinSize = binsize

    while minBinSize < data[-1]
        for item in data:
            bins.append((minBinSize, minBinSize + binsize))
        lowerBound += binsize
    pass
Reply
#2
This question looks a lot like the one from July 21st.
Start with hte answers that were given already.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  need help with binning data figure8 3 2,216 Jul-21-2020, 03:49 PM
Last Post: deanhystad
  binning data stephd 2 4,248 Jan-22-2020, 04:44 PM
Last Post: geer26

Forum Jump:

User Panel Messages

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