Extrapolate the column of data, to get the first and last together
        with the data.
483928
def _extrapolate_cols(self, data, first=True, last=True):
        

        if first:
            pos = self.col_indices[:2]
            first_column = _linear_extrapolate(pos,
                                               (data[:, 0], data[:, 1]),
                                               self.hcol_indices[0])
        if last:
            pos = self.col_indices[-2:]
            last_column = _linear_extrapolate(pos,
                                              (data[:, -2], data[:, -1]),
                                              self.hcol_indices[-1])

        if first and last:
            return np.hstack((np.expand_dims(first_column, 1),
                              data,
                              np.expand_dims(last_column, 1)))
        elif first:
            return np.hstack((np.expand_dims(first_column, 1),
                              data))
        elif last:
            return np.hstack((data,
                              np.expand_dims(last_column, 1)))
        else:
            return data
756209
def trim_empty_columns(self):
    """"""
    if self.nrows != 0 and self.ncols != 0:
      last_col = -1
      for row in self.rows:
        for i in range(last_col + 1, len(row)):
          if not self.is_cell_empty(row[i]):
            last_col = i
      ncols = last_col + 1
      self.rows = [row[:ncols] for row in self.rows]
      self.ncols = ncols
    return self
459484
def get_extra_data(self, data):
        """"""
        result = {}
        for key in data.keys():
            if key.startswith(self.name + '-'):
                new_key = key.replace(self.name + '-', '')
                result[new_key] = data[key]
        return result
461974
def interpolate(v1, v2, t):
    '''
    '''
    return add(v1, mul(sub(v2, v1), t))
1136502
def set_last_col_idx(self, last_col_idx):
		'''
		
		'''
		assert last_col_idx >= self._max_col
		self._max_col = last_col_idx
		return self
380388
def _preprocess(df):
    

    df = df.stack()

    df.index.rename(["id", "time"], inplace=True)  # .reset_index()
    df.name = "value"
    df = df.reset_index()

    return df
1242712
static void columnAverageImpute(double[][] data) throws MissingValueImputationException {
        for (int j = 0; j < data[0].length; j++) {
            int n = 0;
            double sum = 0.0;

            for (int i = 0; i < data.length; i++) {
                if (!Double.isNaN(data[i][j])) {
                    n++;
                    sum += data[i][j];
                }
            }

            if (n == 0) {
                continue;
            }

            if (n < data.length) {
                double avg = sum / n;
                for (int i = 0; i < data.length; i++) {
                    if (Double.isNaN(data[i][j])) {
                        data[i][j] = avg;
                    }
                }
            }
        }
    }
1064479
def getCumPos(data):
    
    pos = getPosNew(data)
    chrom= data.geno['col_header']['chrom'][:]
    n_chroms = int(chrom.max())
    x = 0
    for chrom_i in range(1,n_chroms+1):
        I = chrom==chrom_i
        pos[I]+=x
        x=pos[I].max()
    return pos
433773
def preview(df,preview_rows = 20):#,preview_max_cols = 0):
    
    if preview_rows < 4:
        preview_rows = 4
    preview_rows = min(preview_rows,df.shape[0])
    outer = math.floor(preview_rows / 4)
    return pd.concat([df.head(outer),
                      df[outer:-outer].sample(preview_rows-2*outer),
                      df.tail(outer)])
216993
def interpolate(self, year):
        
        df = self.pivot_table(index=IAMC_IDX, columns=['year'],
                              values='value', aggfunc=np.sum)
        # drop year-rows where values are already defined
        if year in df.columns:
            df = df[np.isnan(df[year])]
        fill_values = df.apply(fill_series,
                               raw=False, axis=1, year=year)
        fill_values = fill_values.dropna().reset_index()
        fill_values = fill_values.rename(columns={0: "value"})
        fill_values['year'] = year
        self.data = self.data.append(fill_values, ignore_index=True)
1143894
def exact(self, column, *values):
        
        df = self._exact(column, *values)
        if df is None:
            self.err("Can not select exact data")
        self.df = df
268644
def extrapolate_points(points, n_points):
    
    points = points[:n_points]
    lat = []
    lon = []
    last = None
    for point in points:
        if last is not None:
            lat.append(last.lat-point.lat)
            lon.append(last.lon-point.lon)
        last = point

    dts = np.mean([p.dt for p in points])
    lons = np.mean(lon)
    lats = np.mean(lat)

    gen_sample = []
    last = points[0]
    for _ in range(n_points):
        point = Point(last.lat+lats, last.lon+lons, None)
        point.dt = dts
        # point.compute_metrics(last)
        gen_sample.append(point)
        last = point

    return gen_sample
557744
def interpolate_slice(slice_rows, slice_cols, interpolator):
    """"""
    fine_rows = np.arange(slice_rows.start, slice_rows.stop, slice_rows.step)
    fine_cols = np.arange(slice_cols.start, slice_cols.stop, slice_cols.step)
    return interpolator(fine_cols, fine_rows)
377509
def _apply_data(self, f, ts, reverse=False):
        
        # TODO: needs to catch np numeric types?
        if isinstance(ts, (int, float)):
            d = ts * np.ones(self.shape[0])
        elif ts is None:
            d = None
        elif np.array_equal(ts.index, self.index):
            d = ts.values
        else:
            d = ts._retime(self.index)

        if not reverse:
            new_data = np.apply_along_axis(f, 0, self.values, d)
        else:
            new_data = np.apply_along_axis(f, 0, d, self.values)
        return Trace(new_data, self.index, name=self.name)
983991
def flatten(self, df, column_name):
        """"""
        _exp_list = [[md5, x] for md5, value_list in zip(df['md5'], df[column_name]) for x in value_list]
        return pd.DataFrame(_exp_list, columns=['md5',column_name])
822191
function(d, val) {
    var wyThur = later.dw.next(later.wy.start(d), 5),
        year = later.date.prevRollover(wyThur, val, later.wy, later.Y);

    // handle case where 1st of year is last week of previous month
    if(later.wy.val(year) !== 1) {
      year = later.dw.next(year, 2);
    }

    var wyMax = later.wy.extent(year)[1],
        wyEnd = later.wy.end(year);

    val = val > wyMax ? wyMax : val || wyMax;

    return later.wy.end(later.date.next(
        later.Y.val(wyEnd),
        later.M.val(wyEnd),
        later.D.val(wyEnd) + 7 * (val-1)
      ));
  }
1083096
def _aggregate(df, by):
    """"""
    by = [by] if isstr(by) else by
    cols = [c for c in list(df.columns) if c not in ['value'] + by]
    return df.groupby(cols).sum()['value']