How can I replace outliers with maximum non-outlier value?
My answer to the first question is use numpy's percentile function. And then, with y being the target vector and Tr the percentile level chose,  try something like

import numpy as np
value = np.percentile(y, Tr)
for i in range(len(y)):
   if y[i] &gt; value:
       y[i]= value


For the second question, I guess I would remove them or replace them with the mean if the outliers are an obvious mistake. But your approach seems reasonable otherwise.