title: How to replace the outliers with the 95th and 5th percentile in Python?
body: <p>I am trying to do an outlier treatment on my time series data where I want to replace the values > 95th percentile with the 95th percentile and the values &lt; 5th percentile with the 5th percentile value. I have prepared some code but I am unable to find the desired result.</p>
  
  <p>I am trying to create a OutlierTreatment function using a sub- function called Cut. The code is given below</p>
  
  <pre><code>def outliertreatment(df,high_limit,low_limit):
      df_temp=df['y'].apply(cut,high_limit,low_limit, extra_kw=1)
      return df_temp
  def cut(column,high_limit,low_limit):
      conds = [column &gt; np.percentile(column, high_limit),
               column &lt; np.percentile(column, low_limit)]
      choices = [np.percentile(column, high_limit),
              np.percentile(column, low_limit)]
      return np.select(conds,choices,column)  
  </code></pre>
  
  <p>I expect to send the dataframe, 95 as high_limit and 5 as low_limit in the OutlierTreatment function. How to achieve the desired result?</p>