Put the data for "col_name" into dataframe with df_name
        Used to add 'site_name' to specimen table, for example.
514063
def propagate_name_down(self, col_name, df_name, verbose=False):
        
        if df_name not in self.tables:
            table = self.add_magic_table(df_name)[1]
            if is_null(table):
                return
        df = self.tables[df_name].df
        if col_name in df.columns:
            if all(df[col_name].apply(not_null)):
                #print('{} already in {}'.format(col_name, df_name))
                return df

        # otherwise, do necessary merges to get col_name into df
        # get names for each level
        grandparent_table_name = col_name.split('_')[0] + "s"
        grandparent_name = grandparent_table_name[:-1]
        ind = self.ancestry.index(grandparent_table_name) - 1
        #
        parent_table_name, parent_name = self.get_table_name(ind)
        child_table_name, child_name = self.get_table_name(ind - 1)
        bottom_table_name, bottom_name = self.get_table_name(ind - 2)

        # merge in bottom level
        if child_name not in df.columns:
            # add child table if missing
            if bottom_table_name not in self.tables:
                result = self.add_magic_table(bottom_table_name)[1]
                if not isinstance(result, MagicDataFrame):
                    if verbose:
                        print("-W- Couldn't read in {} data for data propagation".format(bottom_table_name))
                    return df
            # add child_name to df
            add_df = self.tables[bottom_table_name].df
            # drop duplicate names
            add_df = add_df.drop_duplicates(subset=bottom_name)
            if child_name not in df.columns:
                if verbose:
                    print("-W- Cannot complete propagation, {} table is missing {} column".format(df_name, child_name))
            else:
                add_df = stringify_col(add_df, child_name)
                df = stringify_col(df, bottom_name)
                df = df.merge(add_df[[child_name]],
                              left_on=[bottom_name],
                              right_index=True, how="left")
                self.tables[df_name].df = df

        # merge in one level above
        if parent_name not in df.columns:
            # add parent_table if missing
            if child_table_name not in self.tables:
                result = self.add_magic_table(child_table_name)[1]
                if not isinstance(result, MagicDataFrame):
                    if verbose:
                        print("-W- Couldn't read in {} data".format(child_table_name))
                        print("-I- Make sure you've provided the correct file name")
                    return df
            # add parent_name to df
            add_df = self.tables[child_table_name].df
            # drop duplicate names
            add_df = add_df.drop_duplicates(subset=child_name)
            if parent_name not in add_df:
                if verbose:
                    print('-W- could not finish propagating names: {} table is missing {} column'.format(child_table_name, parent_name))
            elif parent_name not in df:
                if verbose:
                    print('-W- could not finish propagating names: {} table is missing {} column'.format(df_name, parent_name))
            else:
                add_df = stringify_col(add_df, parent_name)
                df = stringify_col(df, child_name)
                df = df.merge(add_df[[parent_name]],
                              left_on=[child_name],
                              right_index=True, how="left")
                self.tables[df_name].df = df

        # merge in two levels above
        if grandparent_name not in df.columns:
            # add grandparent table if it is missing
            if parent_table_name not in self.tables:
                result = self.add_magic_table(parent_table_name)[1]
                if not isinstance(result, MagicDataFrame):
                    if verbose:
                        print("-W- Couldn't read in {} data".format(parent_table_name))
                        print("-I- Make sure you've provided the correct file name")
                    return df
            # add grandparent name to df
            add_df = self.tables[parent_table_name].df
            # drop duplicate names
            add_df = add_df.drop_duplicates(subset=parent_name)
            if grandparent_name not in add_df.columns:
                if verbose:
                    print('-W- could not finish propagating names: {} table is missing {} column'.format(parent_table_name, grandparent_name))
            elif parent_name not in df.columns:
                if verbose:
                    print('-W- could not finish propagating names: {} table is missing {} column'.format(df_name, parent_name))
            else:
                add_df = stringify_col(add_df, grandparent_name)
                df = stringify_col(df, parent_name)
                df = df.merge(add_df[[grandparent_name]],
                              left_on=[parent_name],
                              right_index=True, how="left")
                df = stringify_col(df, grandparent_name)
        # update the Contribution
        self.tables[df_name].df = df
        return df
1285333
def __dump(df,relation='data',description=''):
    
    attrs = []
    for col in df.columns:
        attr = col.split('@')
        if attr[1].count('{')>0 and attr[1].count('}')>0:
            vals = attr[1].replace('{','').replace('}','').split(',')
            attrs.append((attr[0],vals))
        else:
            attrs.append((attr[0],attr[1]))

    data = list(df.values)
    result = {
        'attributes':attrs,
        'data':data,
        'description':description,
        'relation':relation
    }
    return result
299598
def add_sample(self, samp_name, site_name=None, er_data=None, pmag_data=None):
        
        if site_name:
            site = self.find_by_name(site_name, self.sites)
            if not site:
                print("""-W- {} is not a currently existing site.
Creating a new site named: {} """.format(site_name, site_name))
                site = self.add_site(site_name)
        else:
            site = None
        sample = Sample(samp_name, site, self.data_model, er_data, pmag_data)
        self.samples.append(sample)
        if site:
            site.samples.append(sample)
        return sample
1367830
def _set_column_names(dep, exp):
    
    colnames = exp['Experiment'].astype(str) + '_' + exp['Fraction'].astype(str)
    file2col = dict(zip(exp['Raw file'], colnames))
    _dep = dep.rename(columns=file2col)
    _dep.columns.name = 'Column Name'
    return _dep
791951
def append_metrics(self, metrics, df_name):
        
        dataframe = self._dataframes[df_name]
        _add_new_columns(dataframe, metrics)
        dataframe.loc[len(dataframe)] = metrics
1090400
def col(self, col_name_or_num):
        
        if isinstance(col_name_or_num, basestring):
            return self[col_name_or_num]
        elif isinstance(col_name_or_num, (int, long)):
            if col_name_or_num > len(self.fields):
                raise IndexError("Invalid column index `%s` for DataTable" %
                                 col_name_or_num)
            return self.__data[self.fields[col_name_or_num]]
53428
def sample_df(self, pstates=None, n_obs=None, random_state=None, pstate_col=PSTATE_COL, hstate_col=HSTATE_COL):
        
        try:
            import pandas as pd
        except Exception as e:
            raise e

        obs, pstates, hstates = self.sample(pstates, n_obs, random_state)
        items = []

        if pstate_col is not None:
            items.append((pstate_col, pstates))

        if hstate_col is not None:
            items.append((hstate_col, hstates))

        items = items + [(self.emission_name[i], obs[:, i]) for i in range(self.n_features)]
        df = pd.DataFrame.from_items(items)
        return df
459456
def addColumn(self, col, index=None):
        ''
        if col:
            if index is None:
                index = len(self.columns)
            col.sheet = self
            self.columns.insert(index, col)
            return col
711624
def build_conversion_table(self, dataframes):
        
        self.data = pd.DataFrame(dataframes)
        tmp_pairs = [s.split("/") for s in self.data.columns]
        self.data.columns = pd.MultiIndex.from_tuples(tmp_pairs)
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)
1337845
def add_sample(self, **data):
        """"""
        missing_dimensions = set(data).difference(self.dimensions)

        if missing_dimensions:
            raise KeyError('Dimensions not defined in this series: %s'
                           % ', '.join(missing_dimensions))

        for dim in self.dimensions:
            getattr(self, dim).append(data.get(dim))
256920
def dataframe_to_xml(df, name, roffset, coffset, rows, cols, format):
    
    num_rows = min(df.shape[0], MAX_SLICE_SIZE)
    num_cols = min(df.shape[1], MAX_SLICE_SIZE)
    if (num_rows, num_cols) != df.shape:
        df = df.iloc[0:num_rows, 0: num_cols]
        slice = '.iloc[0:%s, 0:%s]' % (num_rows, num_cols)
    else:
        slice = ''
    slice = name + slice
    xml = '<array slice=\"%s\" rows=\"%s\" cols=\"%s\" format=\"\" type=\"\" max=\"0\" min=\"0\"/>\n' % \
          (slice, num_rows, num_cols)

    if (rows, cols) == (-1, -1):
        rows, cols = num_rows, num_cols

    rows = min(rows, MAXIMUM_ARRAY_SIZE)
    cols = min(min(cols, MAXIMUM_ARRAY_SIZE), num_cols)
    # need to precompute column bounds here before slicing!
    col_bounds = [None] * cols
    for col in xrange(cols):
        dtype = df.dtypes.iloc[coffset + col].kind
        if dtype in "biufc":
            cvalues = df.iloc[:, coffset + col]
            bounds = (cvalues.min(), cvalues.max())
        else:
            bounds = (0, 0)
        col_bounds[col] = bounds

    df = df.iloc[roffset: roffset + rows, coffset: coffset + cols]
    rows, cols = df.shape

    xml += "<headerdata rows=\"%s\" cols=\"%s\">\n" % (rows, cols)
    format = format.replace('%', '')
    col_formats = []

    get_label = lambda label: str(label) if not isinstance(label, tuple) else '/'.join(map(str, label))

    for col in xrange(cols):
        dtype = df.dtypes.iloc[col].kind
        if dtype == 'f' and format:
            fmt = format
        elif dtype == 'f':
            fmt = '.5f'
        elif dtype == 'i' or dtype == 'u':
            fmt = 'd'
        else:
            fmt = 's'
        col_formats.append('%' + fmt)
        bounds = col_bounds[col]

        xml += '<colheader index=\"%s\" label=\"%s\" type=\"%s\" format=\"%s\" max=\"%s\" min=\"%s\" />\n' % \
               (str(col), get_label(df.axes[1].values[col]), dtype, fmt, bounds[1], bounds[0])
    for row, label in enumerate(iter(df.axes[0])):
        xml += "<rowheader index=\"%s\" label = \"%s\"/>\n" % \
               (str(row), get_label(label))
    xml += "</headerdata>\n"
    xml += "<arraydata rows=\"%s\" cols=\"%s\"/>\n" % (rows, cols)
    for row in xrange(rows):
        xml += "<row index=\"%s\"/>\n" % str(row)
        for col in xrange(cols):
            value = df.iat[row, col]
            value = col_formats[col] % value
            xml += var_to_xml(value, '')
    return xml
623466
def indexcol(self, col: str):
        
        try:
            self.df[col] = self.df.index.values
        except Exception as e:
            self.err(e)
            return
        self.ok("Column", col, "added from the index")
635186
def add_data_to_df(self, data: np.array):
        """"""

        col_names = ['high_p', 'low_p', 'open_p', 'close_p', 'volume', 'oi']

        data = np.array(data).reshape(-1, len(col_names) + 1)
        df = pd.DataFrame(data=data[:, 1:], index=data[:, 0],
                          columns=col_names)

        df.index = pd.to_datetime(df.index)

        # Sort the dataframe based on ascending dates.
        df.sort_index(ascending=True, inplace=True)

        # Convert dataframe columns to float and ints.
        df[['high_p', 'low_p', 'open_p', 'close_p']] = df[
            ['high_p', 'low_p', 'open_p', 'close_p']].astype(float)
        df[['volume', 'oi']] = df[['volume', 'oi']].astype(int)

        if self._ndf.empty:
            self._ndf = df
        else:
            self._ndf = self._ndf.append(df)
382810
def _construct_df(self, mol2_lines, col_names, col_types):
        """"""
        return self._atomsection_to_pandas(self._get_atomsection(mol2_lines),
                                           col_names=col_names,
                                           col_types=col_types)
197580
def from_dataframe(dataframe, table_name=""):
        

        return TableData(table_name, list(dataframe.columns.values), dataframe.values.tolist())
785461
def combine_dfs(dfs, names, method):
    """"""
    if method == "track":
        res = list()
        for df, identifier in zip(dfs, names):
            df["dataset"] = identifier
            res.append(df)
        return pd.concat(res, ignore_index=True)
    elif method == "simple":
        return pd.concat(dfs, ignore_index=True)