I originally had the function below to convert values of None into values of NaN, but realized it is much faster and easier to coerce the array type:
x.astype(float)
Here’s the slow way to do it:
from numpy import array, nan
def None2NaN(x):
"""Converts None objects to nan, for use in
NumPy arrays. Returns an array."""
newlist = []
for i in x:
if i is not None:
newlist.append(i)
else:
newlist.append(nan)
return array(newlist)