Take in a pandas DataFrame, and return a list of columns
    that are in that DataFrame AND should be between 0 - 360 degrees.
5716
def get_degree_cols(df):
    
    vals = ['lon_w', 'lon_e', 'lat_lon_precision', 'pole_lon',
            'paleolon', 'paleolon_sigma',
            'lon', 'lon_sigma', 'vgp_lon', 'paleo_lon', 'paleo_lon_sigma',
            'azimuth', 'azimuth_dec_correction', 'dir_dec',
            'geographic_precision', 'bed_dip_direction']
    relevant_cols = list(set(vals).intersection(df.columns))
    return relevant_cols
446661
def _maybe_pandas_data(data, feature_names, feature_types):
    

    if not isinstance(data, DataFrame):
        return data, feature_names, feature_types

    data_dtypes = data.dtypes
    if not all(dtype.name in PANDAS_DTYPE_MAPPER for dtype in data_dtypes):
        bad_fields = [data.columns[i] for i, dtype in
                      enumerate(data_dtypes) if dtype.name not in PANDAS_DTYPE_MAPPER]

        msg = """DataFrame.dtypes for data must be int, float or bool.
                Did not expect the data types in fields """
        raise ValueError(msg + ', '.join(bad_fields))

    if feature_names is None:
        if isinstance(data.columns, MultiIndex):
            feature_names = [
                ' '.join([str(x) for x in i])
                for i in data.columns
            ]
        else:
            feature_names = data.columns.format()

    if feature_types is None:
        feature_types = [PANDAS_DTYPE_MAPPER[dtype.name] for dtype in data_dtypes]

    data = data.values.astype('float')

    return data, feature_names, feature_types
530077
def _maybe_from_pandas(data, feature_names, feature_types):
    
    try:
        import pandas as pd
    except ImportError:
        return data, feature_names, feature_types

    if not isinstance(data, pd.DataFrame):
        return data, feature_names, feature_types

    dtypes = data.dtypes
    if not all(dtype.name in ('int64', 'float64', 'bool') for dtype in dtypes):
        raise ValueError('DataFrame.dtypes must be int, float or bool')

    if feature_names is None:
        feature_names = data.columns.format()
    if feature_types is None:
        mapper = {'int64': 'int', 'float64': 'q', 'bool': 'i'}
        feature_types = [mapper[dtype.name] for dtype in dtypes]
    data = data.values.astype('float')
    return data, feature_names, feature_types
1099551
def stoch(df, window=14, d=3, k=3, fast=False):
    

    my_df = pd.DataFrame(index=df.index)

    my_df['rolling_max'] = df['high'].rolling(window).max()
    my_df['rolling_min'] = df['low'].rolling(window).min()

    my_df['fast_k'] = 100 * (df['close'] - my_df['rolling_min'])/(my_df['rolling_max'] - my_df['rolling_min'])
    my_df['fast_d'] = my_df['fast_k'].rolling(d).mean()

    if fast:
        return my_df.loc[:, ['fast_k', 'fast_d']]

    my_df['slow_k'] = my_df['fast_k'].rolling(k).mean()
    my_df['slow_d'] = my_df['slow_k'].rolling(d).mean()

    return my_df.loc[:, ['slow_k', 'slow_d']]
95424
def cols_(self) -> pd.DataFrame:
        
        try:
            s = self.df.iloc[0]
            df = pd.DataFrame(s)
            df = df.rename(columns={0: "value"})

            def run(row):
                t = row[0]
                return type(t).__name__

            s = df.apply(run, axis=1)
            df = df.rename(columns={0: "value"})
            df["types"] = s
            return df
        except Exception as e:
            self.err(e)
798062
def get_column_names(self, X):
        
        if isinstance(X, pd.DataFrame):
            return X.columns

        return range(X.shape[1])
1121871
def _edge_list_to_dataframe(ls, src_column_name, dst_column_name):
    
    assert HAS_PANDAS, 'Cannot use dataframe because Pandas is not available or version is too low.'
    cols = reduce(set.union, (set(e.attr.keys()) for e in ls))
    df = pd.DataFrame({
        src_column_name: [e.src_vid for e in ls],
        dst_column_name: [e.dst_vid for e in ls]})
    for c in cols:
        df[c] = [e.attr.get(c) for e in ls]
    return df
533663
def confusion(df, labels=['neg', 'pos']):
    
    c = pd.DataFrame(np.zeros((2, 2)), dtype=int)
    a, b = df.columns[:2]  # labels[df.columns[:2]]
    c.columns = sorted(set(df[a]))[:2]
    c.columns.name = a
    c.index = list(c.columns)
    c.index.name = b
    c1, c2 = c.columns
    c[c1][c1] = ((df[a] == c1) & (df[b] == c1)).sum()
    c[c1][c2] = ((df[a] == c1) & (df[b] == c2)).sum()
    c[c2][c2] = ((df[a] == c2) & (df[b] == c2)).sum()
    c[c2][c1] = ((df[a] == c2) & (df[b] == c1)).sum()
    return c
268170
def normalize_column_names(df):
    
    """
    columns = df.columns if hasattr(df, 'columns') else df
    columns = [c.lower().replace(' ', '_') for c in columns]
    return columns
1067240
def _unpack_dataframes(dfs):
    
    col_groups = defaultdict(list)
    columns = dfs[0].columns
    for col in columns:
        key, *loc = col.split(".")
        loc = tuple(int(i) - 1 for i in loc)
        col_groups[key].append((col, loc))

    chains = len(dfs)
    draws = len(dfs[0])
    sample = {}
    for key, cols_locs in col_groups.items():
        ndim = np.array([loc for _, loc in cols_locs]).max(0) + 1
        sample[key] = np.full((chains, draws, *ndim), np.nan)
        for col, loc in cols_locs:
            for chain_id, df in enumerate(dfs):
                draw = df[col].values
                if loc == ():
                    sample[key][chain_id, :] = draw
                else:
                    axis1_all = range(sample[key].shape[1])
                    slicer = (chain_id, axis1_all, *loc)
                    sample[key][slicer] = draw
    return sample
655070
def from_columns(columns):
        
        data = [
            [
                column[i]
                for i in range(len(column))
            ]
            for column in columns
        ]
        return Matrix(data)
473179
def _itertuples(df):
    
    cols = [df.iloc[:, k] for k in range(len(df.columns))]
    return zip(df.index, *cols)
497790
def to_df(self) -> pd.DataFrame:
        """"""
        df = pd.DataFrame(index=RangeIndex(0, self.shape[0], name=None))
        for key in self.keys():
            value = self[key]
            for icolumn, column in enumerate(value.T):
                df['{}{}'.format(key, icolumn+1)] = column
        return df
117095
def column_stack_2d(data):
    """"""
    return list(list(itt.chain.from_iterable(_)) for _ in zip(*data))
929940
def column_correlations(self, X):
        """"""
        utils.validation.check_is_fitted(self, 's_')

        # Convert numpy array to pandas DataFrame
        if isinstance(X, np.ndarray):
            X = pd.DataFrame(X)

        row_pc = self.row_coordinates(X)

        return pd.DataFrame({
            component: {
                feature: row_pc[component].corr(X[feature])
                for feature in X.columns
            }
            for component in row_pc.columns
        })
956708
def _dataframe_to_vertex_list(df):
    
    cols = df.columns
    if len(cols):
        assert _VID_COLUMN in cols, "Vertex DataFrame must contain column %s" % _VID_COLUMN
        df = df[cols].T
        ret = [Vertex(None, _series=df[col]) for col in df]
        return ret
    else:
        return []
384036
def PyobjColumns(obj):
    ''
    return [ColumnAttr(k, type(getattr(obj, k))) for k in getPublicAttrs(obj)]