def original_app(data, win_size):
    result = np.zeros(data.size)
for count in range(data.size):
    part_data = data[max(count - (win_size - 1) / 2, 0):min(count + (
        win_size + 1) / 2, data.size)]
mask = np.isfinite(part_data)
if np.sum(mask) != 0:
    result[count] = np.sum(part_data[mask]) / np.sum(mask)
else:
    result[count] = None
return result

def numpy_app(data, win_size):
    mask = np.isnan(data)
K = np.ones(win_size, dtype=int)
out = np.convolve(np.where(mask, 0, data), K) / np.convolve(~mask, K)
return out[1:-1]
Python: Sliding windowed mean, ignoring missing data