Computes the variance inflation factor (VIF) for each column in the df.
    Returns a pandas Series of VIFs

    Args:
        df: pandas DataFrame with columns to run diagnostics on
548666
def variance_inflation_factors(df):
    '''
    
    '''
    corr = np.corrcoef(df, rowvar=0)
    corr_inv = np.linalg.inv(corr)
    vifs = np.diagonal(corr_inv)
    return pd.Series(vifs, df.columns, name='VIF')
409381
def generate_simple_vcf(filename, variant_collection):
    
    contigs = []
    positions = []
    refs = []
    alts = []
    for variant in variant_collection:
        contigs.append("chr" + variant.contig)
        positions.append(variant.start)
        refs.append(variant.ref)
        alts.append(variant.alt)
    df = pd.DataFrame()
    df["contig"] = contigs
    df["position"] = positions
    df["id"] = ["."] * len(variant_collection)
    df["ref"] = refs
    df["alt"] = alts
    df["qual"] = ["."] * len(variant_collection)
    df["filter"] = ["."] * len(variant_collection)
    df["info"] = ["."] * len(variant_collection)
    df["format"] = ["GT:AD:DP"] * len(variant_collection)
    normal_ref_depths = [randint(1, 10) for v in variant_collection]
    normal_alt_depths = [randint(1, 10) for v in variant_collection]
    df["n1"] = ["0:%d,%d:%d" % (normal_ref_depths[i], normal_alt_depths[i],
                                normal_ref_depths[i] + normal_alt_depths[i])
                for i in range(len(variant_collection))]
    tumor_ref_depths = [randint(1, 10) for v in variant_collection]
    tumor_alt_depths = [randint(1, 10) for v in variant_collection]
    df["t1"] = ["0/1:%d,%d:%d" % (tumor_ref_depths[i], tumor_alt_depths[i], tumor_ref_depths[i] + tumor_alt_depths[i])
                for i in range(len(variant_collection))]

    with open(filename, "w") as f:
        f.write("##fileformat=VCFv4.1\n")
        f.write("##reference=file:///projects/ngs/resources/gatk/2.3/ucsc.hg19.fasta\n")

    with open(filename, "a") as f:
        df.to_csv(f, sep="\t", index=None, header=None)
452171
def cdf(data,mode='continuous',**kwargs):
  '''

  '''

  return ( np.linspace(0.0,1.0,len(data)), np.sort(data) )
1212135
def _get_mvar(cls, df, column, windows):
        
        window = cls.get_only_one_positive_int(windows)
        column_name = '{}_{}_mvar'.format(column, window)
        df[column_name] = df[column].rolling(
            min_periods=1, window=window, center=False).var()
528546
def get_term_freq_df(self, label_append=' freq'):
        '''
        
        '''

        '''
        row = self._row_category_ids()
        newX = csr_matrix((self._X.data, (row, self._X.indices)))
        return self._term_freq_df_from_matrix(newX)
        '''
        mat = self.get_term_freq_mat()
        return pd.DataFrame(mat,
                            index=pd.Series(self.get_terms(), name='term'),
                            columns=[c + label_append for c in self.get_categories()])
857988
def _get_wr(cls, df, n_days):
        
        n_days = int(n_days)
        ln = df['low'].rolling(min_periods=1, window=n_days,
                               center=False).min()

        hn = df['high'].rolling(min_periods=1, window=n_days,
                                center=False).max()
        column_name = 'wr_{}'.format(n_days)
        df[column_name] = (hn - df['close']) / (hn - ln) * 100
1071755
def multi_shift(df, window):
    
    if isinstance(df, pd.Series):
        df = pd.DataFrame(df)

    dfs = [df.shift(i) for i in np.arange(window)]
    for ix, df_item in enumerate(dfs[1:]):
        dfs[ix + 1].columns = [str(col) for col in df_item.columns + str(ix + 1)]
    return pd.concat(dfs, 1, sort=True)
306737
def var(series):
    
    if np.issubdtype(series.dtype, np.number):
        return series.var()
    else:
        return np.nan
1335353
def train_df(self, df):
        
        aesthetics = sorted(set(self.aesthetics) & set(df.columns))
        for ae in aesthetics:
            self.train(df[ae])
1217315
def to_df(self):
        
        df = pd.DataFrame()
        name = []
        band = []
        resolution = []
        mag = []
        e_mag = []
        separation = []
        pa = []
        relative = []
        for o in self._observations:
            for s in o.sources:
                name.append(o.name)
                band.append(o.band)
                resolution.append(o.resolution)
                mag.append(s.mag)
                e_mag.append(s.e_mag)
                separation.append(s.separation)
                pa.append(s.pa)
                relative.append(s.relative)

        return pd.DataFrame({'name':name,'band':band,'resolution':resolution,
                             'mag':mag,'e_mag':e_mag,'separation':separation,
                             'pa':pa,'relative':relative})
338723
def vcf_to_df(canvasvcfs, exonbed, cpus):
    
    df = pd.DataFrame()
    p = Pool(processes=cpus)
    results = []
    args = [(x, exonbed, i) for (i, x) in enumerate(canvasvcfs)]
    r = p.map_async(vcf_to_df_worker, args,
                    callback=results.append)
    r.wait()

    for res in results:
        df = df.append(res, ignore_index=True)
    return df
79099
def gen_FS_DF(df_output):
    
    df_day = pd.pivot_table(
        df_output,
        values=['T2', 'U10', 'Kdown', 'RH2'],
        index=['Year', 'Month', 'Day'],
        aggfunc=[min, max, np.mean, ])
    df_day_all_year = pd.pivot_table(
        df_output,
        values=['T2', 'U10', 'Kdown', 'RH2'],
        index=['Month', 'Day'],
        aggfunc=[min, max, np.mean, ])

    array_yr_mon = df_day.index.droplevel(
        'Day').to_frame().drop_duplicates().values

    df_fs = pd.DataFrame(
        {(yr, mon):
         (df_day.loc[(yr, mon)].apply(gen_score_ser) -
          df_day_all_year.loc[mon].apply(gen_score_ser)).abs().mean()
         for yr, mon in array_yr_mon})

    return df_fs
804891
def _to_df(self, query, conn, index_col=None, coerce_float=True, params=None,
               parse_dates=None, columns=None):
        
        return pd.io.sql.read_sql(str(query), conn, index_col=index_col,
                                  coerce_float=coerce_float, params=params,
                                  parse_dates=parse_dates, columns=columns)
260460
def explain_prediction_df(estimator, doc, **kwargs):
    # type: (...) -> pd.DataFrame
    
    kwargs = _set_defaults(kwargs)
    return format_as_dataframe(
        eli5.explain_prediction(estimator, doc, **kwargs))
223943
def to_df(self):
        ''''''
        return pd.DataFrame({k: v for k, v in self.items() if k is not 'names'},
                            index=self['names'])
1246822
def map_df(self, df):
        
        if (len(df) == 0) or (len(self) == 0):
            return df

        # Each scale maps the columns it understands
        for sc in self:
            df = sc.map_df(df)
        return df
154349
def cdf(x, df, loc=0.0, scale=1.0, gamma = 1.0):
        
        result = np.zeros(x.shape[0])
        result[x<0] = 2.0/(np.power(gamma,2) + 1.0)*ss.t.cdf(gamma*(x[x-loc < 0]-loc[x-loc < 0])/scale, df=df)
        result[x>=0] = 1.0/(np.power(gamma,2) + 1.0) + 2.0/((1.0/np.power(gamma,2)) + 1.0)*(ss.t.cdf((x[x-loc >= 0]-loc[x-loc >= 0])/(gamma*scale), df=df)-0.5)
        return result