I am trying to run a code to build histogram from a list of data and keep getting the below error :
Error:TypeError: list indices must be integers or slices, not float
Below is my code, can you help me with what i am doing wrong?%matplotlib inline import numpy as np import matplotlib.pyplot as plt from helper import plotHisto data = np.loadtxt('math_scores.txt') def myMap(inp, f) : res = [] for i in inp : res.append(f(i)) return res def new(x) : return int(x) pdata = myMap(data, new) def buildHisto(pdata, numbins, minimum, maximum) : minimum = min(pdata) maximum = max(pdata) diff = maximum - minimum binwidth = diff/numbins histo = [] for d in pdata : histo[d//binwidth]+=1 return histo histo = buildHisto(pdata, 10, minimum, maximum) plotHisto(histo, 'histo1.png', minimum, maximum, plotinline = True)