def drop_nans(X, y=None):
    total = X.shape[1]
new_thresh = total - thresh
df = pd.DataFrame(X)
df.dropna(thresh=new_thresh, inplace=True)
return df.values
Custom transformer for sklearn Pipeline that alters both X and y