code: def truncate_weights(weights, min_weight=0.01, rescale=True):
      
      if not isinstance(weights, pd.Series):
          raise ValueError("Weight vector is not a Series")
  
      adj_weights = weights[:]
      adj_weights[adj_weights.abs() < min_weight] = 0.0
  
      if rescale:
          if not adj_weights.sum():
              raise ValueError("Cannot rescale weight vector as sum is not finite")
          
          adj_weights /= adj_weights.sum()
  
      return adj_weights
docs: Truncates small weight vectors, i.e. sets weights below a treshold to zero.
      This can be helpful to remove portfolio weights, which are negligibly small.
      
      Parameters
      ----------
      weights: pandas.Series
          Optimal asset weights.
      min_weight: float, optional
          All weights, for which the absolute value is smaller
          than this parameter will be set to zero.
      rescale: boolean, optional
          If 'True', rescale weights so that weights.sum() == 1.
          If 'False', do not rescale.
  
      Returns
      -------
      adj_weights: pandas.Series
          Adjusted weights.