code: def trim_data(x):
      
      # Find indices for first and last valid data
      first = 0
      while np.isnan(x[first]):
          first += 1
      last = len(x)
      while np.isnan(x[last - 1]):
          last -= 1
      return x[first:last]
docs: Trim leading and trailing NaNs from dataset
      This is done by browsing the array from each end and store the index of the
      first non-NaN in each case, the return the appropriate slice of the array