I am trying to make a histogram in numpy but numpy.histogram seems to really hate NaN values. I have tried removing NaN values from a list called data in three different ways and Quantopian doesn't let me use any of those three ways: 1.) TypeError: only integer arrays with one element can be converted to an index
data = data[~np.isnan(data)]
2.) So then I tried using pandas.dropna() and it threw: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
datapd = pd.Series(data) hist, bins = np.histogram(datapd.dropna(), density=True, bins = 'auto')
3.) And when that didn't work I tried removing them on my own:
i = 0 while(i < len(y)): if(float('nan') == y[i]): y[i] = 0 i = i + 1
It threw the same error: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
How do you remove NaN values in quantopian? I tried these methods in a python console and it worked I have no clue as to why it wouldn't work in quantopian.