当前位置: 首页>>代码示例>>Python>>正文


Python table.Table类代码示例

本文整理汇总了Python中Orange.data.table.Table的典型用法代码示例。如果您正苦于以下问题:Python Table类的具体用法?Python Table怎么用?Python Table使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Table类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_url

    def load_url(self, from_reload=False):
        url = self.combo.currentText()
        if not url:
            return
        prev_table = self.table
        try:
            with self.progressBar(3) as progress:
                progress.advance()
                table = Table.from_url(url)
                progress.advance()
        except Exception as e:
            log.exception("Couldn't load data from: %s", url)
            self.Error.error(try_(lambda: e.args[0], ''))
            self.table = None
        else:
            self.Error.clear()
            self.table = table
            self.combo.setTitleFor(self.combo.currentIndex(), table.name)
        self.set_info()

        def _equal(data1, data2):
            NAN = float('nan')
            return (try_(lambda: data1.checksum(), NAN) ==
                    try_(lambda: data2.checksum(), NAN))

        if not (from_reload and _equal(prev_table, self.table)):
            self.commit()
开发者ID:biolab,项目名称:orange3-prototypes,代码行数:27,代码来源:owgooglesheets.py

示例2: commit

 def commit(self):
     continuizer = self.constructContinuizer()
     if self.data is not None:
         domain = continuizer(self.data)
         data = Table.from_table(domain, self.data)
         self.send("Data", data)
     else:
         self.send("Data", None)
开发者ID:Micseb,项目名称:orange3,代码行数:8,代码来源:owcontinuize.py

示例3: set_tree

    def set_tree(self, model=None):
        """When a different tree is given."""
        self.clear()
        self.model = model

        if model is not None:
            # We need to know what kind of tree we have in order to properly
            # show colors and tooltips
            if isinstance(model, TreeClassifier):
                self.tree_type = self.CLASSIFICATION
            elif isinstance(model, TreeRegressor):
                self.tree_type = self.REGRESSION
            else:
                self.tree_type = self.GENERAL

            self.instances = model.instances
            # this bit is important for the regression classifier
            if self.instances is not None and \
                    self.instances.domain != model.domain:
                self.clf_dataset = Table.from_table(
                    self.model.domain, self.instances)
            else:
                self.clf_dataset = self.instances

            self.tree_adapter = self._get_tree_adapter(self.model)
            self.color_palette = self._tree_specific('_get_color_palette')()

            self.ptree.clear()
            self.ptree.set_tree(self.tree_adapter)
            self.ptree.set_tooltip_func(self._tree_specific('_get_tooltip'))
            self.ptree.set_node_color_func(
                self._tree_specific('_get_node_color')
            )

            self._tree_specific('_update_legend_colors')()
            self._update_legend_visibility()

            self._update_info_box()
            self._update_depth_slider()

            self._tree_specific('_update_target_class_combo')()

            self._update_main_area()

            # Get meta variables describing pythagoras tree if given from
            # forest.
            if hasattr(model, 'meta_size_calc_idx'):
                self.size_calc_idx = model.meta_size_calc_idx
            if hasattr(model, 'meta_size_log_scale'):
                self.size_log_scale = model.meta_size_log_scale
            # Updating the size calc redraws the whole tree
            if hasattr(model, 'meta_size_calc_idx') or \
                    hasattr(model, 'meta_size_log_scale'):
                self.update_size_calc()
            # The target class can also be passed from the meta properties
            if hasattr(model, 'meta_target_class_index'):
                self.target_class_index = model.meta_target_class_index
                self.update_colors()
开发者ID:tomazc,项目名称:orange3,代码行数:58,代码来源:owpythagorastree.py

示例4: sendData

 def sendData(self):
     continuizer = self.constructContinuizer()
     if self.data is not None:
         domain = continuizer(self.data)
         data = Table.from_table(domain, self.data)
         self.send("Data", data)
     else:
         self.sendData("Data", None)
     self.data_changed = False
开发者ID:CHANAYA,项目名称:orange3,代码行数:9,代码来源:owcontinuize.py

示例5: redo

    def redo(self):
        self.classValuesModel.append(self.newClassLabel)
        newdomain = Domain([ContinuousVariable(self.widget.attr1),
                            ContinuousVariable(self.widget.attr2)],
                           DiscreteVariable("Class",
                                            values=self.classValuesModel))
        newdata = Table(newdomain)
        instances = [Instance(newdomain,
                              [float(ex[a]) for a in ex.domain.attributes] +
                              [str(ex.get_class())]) for ex in self.data]

        newdata.extend(instances)
        self.widget.data = newdata
        self.widget.removeClassLabel.setEnabled(len(self.classValuesModel) > 1)
        newindex = self.classValuesModel.index(len(self.classValuesModel) - 1)
        self.widget.classValuesView.selectionModel().select(
            newindex, QtGui.QItemSelectionModel.ClearAndSelect)
        self.widget.updatePlot()
        self.widget.updateCursor()
开发者ID:CHANAYA,项目名称:orange3,代码行数:19,代码来源:owpaintdata.py

示例6: from_table

    def from_table(cls, domain, source, row_indices=...):
        """
        Create a new table from selected columns and/or rows of an existing
        one. The columns are chosen using a domain. The domain may also include
        variables that do not appear in the source table; they are computed
        from source variables if possible.

        The resulting data may be a
        - new LazyTable if source is a LazyTable, domain contains only
          attributes of the source and row_indices is not specified.
          This should ensure that the SelectAttributes widget works.
        - a normal Table otherwise, which could apparently be view or a copy
          of the existing data. However, what happens with a view of
          growing data is unknown.

        :param domain: the domain for the new table
        :type domain: Orange.data.Domain
        :param source: the source table
        :type source: Orange.data.Table
        :param row_indices: indices of the rows to include
        :type row_indices: a slice or a sequence
        :return: a new table
        :rtype: Orange.data.Table
        """
        # TODO: Improve the lazyness support for other cases?
        # TODO: Investigate this computing of new variables.
        subdomain = all(v in source.domain for v in domain)
        
        if isinstance(source, LazyTable) and subdomain:
            table_new = LazyTable.from_domain(domain)
            table_new.stop_pulling = True # Should only be done by first LazyTable?
            table_new.table_origin = source
            # Fill the table with the rows that were already materialized.
            # TODO: Do something smarter here?
            #   Definitely, currently we need the copy.copy to prevent 
            #   RuntimeError: dictionary changed size during iteration
            for row_index_full in copy.copy(table_new.table_origin.row_mapping):
                for variable in table_new.domain:
                    # pylint: disable=unused-variable
                    value = table_new[row_index_full][variable]
        else:
            table_new = Table.from_table(
                domain=domain,
                source=source,
                row_indices=row_indices,
            )

        return table_new
开发者ID:hugobuddel,项目名称:orange3,代码行数:48,代码来源:lazytable.py

示例7: retrieve

 def retrieve(self, url):
     if not url: return
     progress = gui.ProgressBar(self, 10)
     for i in range(3): progress.advance()
     try: table = Table.from_url(url)
     except Exception as e:
         import traceback
         log.error(traceback.format_exc())
         log.error("Couldn't load spreadsheet %s: %s", url, e)
         self.error("Couldn't load spreadsheet. Ensure correct read permissions; rectangular, top-left aligned sheet data ...")
         return
     else:
         for i in range(7): progress.advance()
     finally:
         progress.finish()
     return table
开发者ID:thocevar,项目名称:orange3-prototypes,代码行数:16,代码来源:owgooglesheets.py

示例8: apply_domain_edit

    def apply_domain_edit(self):
        if self.data is None:
            table = None
        else:
            domain, cols = self.domain_editor.get_domain(self.data.domain, self.data)
            if not (domain.variables or domain.metas):
                table = None
            else:
                X, y, m = cols
                table = Table.from_numpy(domain, X, y, m, self.data.W)
                table.name = self.data.name
                table.ids = np.array(self.data.ids)
                table.attributes = getattr(self.data, 'attributes', {})

        self.Outputs.data.send(table)
        self.apply_button.setEnabled(False)
开发者ID:ales-erjavec,项目名称:orange3,代码行数:16,代码来源:owfile.py

示例9: apply_domain_edit

    def apply_domain_edit(self):
        attributes = []
        class_vars = []
        metas = []
        places = [attributes, class_vars, metas]
        X, y, m = [], [], []
        cols = [X, y, m]  # Xcols, Ycols, Mcols

        def is_missing(x):
            return str(x) in ("nan", "")

        for column, (name, tpe, place, vals, is_con), (orig_var, orig_plc) in \
            zip(count(), self.editor_model.variables,
                chain([(at, 0) for at in self.data.domain.attributes],
                      [(cl, 1) for cl in self.data.domain.class_vars],
                      [(mt, 2) for mt in self.data.domain.metas])):
            if place == 3:
                continue
            if orig_plc == 2:
                col_data = list(chain(*self.data[:, orig_var].metas))
            else:
                col_data = list(chain(*self.data[:, orig_var]))
            if name == orig_var.name and tpe == type(orig_var):
                var = orig_var
            elif tpe == DiscreteVariable:
                values = list(str(i) for i in set(col_data) if not is_missing(i))
                var = tpe(name, values)
                col_data = [np.nan if is_missing(x) else values.index(str(x))
                            for x in col_data]
            elif tpe == StringVariable and type(orig_var) == DiscreteVariable:
                var = tpe(name)
                col_data = [orig_var.repr_val(x) if not np.isnan(x) else ""
                            for x in col_data]
            else:
                var = tpe(name)
            places[place].append(var)
            cols[place].append(col_data)
        domain = Domain(attributes, class_vars, metas)
        X = np.array(X).T if len(X) else np.empty((len(self.data), 0))
        y = np.array(y).T if len(y) else None
        dtpe = object if any(isinstance(m, StringVariable)
                             for m in domain.metas) else float
        m = np.array(m, dtype=dtpe).T if len(m) else None
        table = Table.from_numpy(domain, X, y, m, self.data.W)
        self.send("Data", table)
        self.apply_button.setEnabled(False)
开发者ID:rekonder,项目名称:orange3,代码行数:46,代码来源:owfile.py

示例10: insert_topics_into_corpus

    def insert_topics_into_corpus(self, corp_in):
        """
        Insert topical representation into corpus.

        :param corp_in: Corpus into whic we want to insert topical representations
        :return: `Orange.data.table.Table`
        """
        matrix = matutils.corpus2dense(self.corpus,
                                       num_terms=self.num_topics).T

        # Generate the new table.
        attr = [ContinuousVariable(n) for n in self.topic_names]
        domain = Domain(attr,
                        corp_in.domain.class_vars,
                        metas=corp_in.domain.metas)

        return Table.from_numpy(domain,
                                matrix,
                                Y=corp_in._Y,
                                metas=corp_in.metas)
开发者ID:pombredanne,项目名称:orange3-text,代码行数:20,代码来源:lda.py

示例11: get_all_topics_table

    def get_all_topics_table(self):
        """ Transform all topics from gensim model to table. """
        all_words = self._topics_words(self.n_words)
        all_weights = self._topics_weights(self.n_words)
        sorted_words = sorted(all_words[0])
        n_topics = len(all_words)

        X = []
        for words, weights in zip(all_words, all_weights):
            weights = [we for wo, we in sorted(zip(words, weights))]
            X.append(weights)
        X = np.array(X).T

        # take only first n_topics; e.g. when user requested 10, but gensim
        # returns only 9 — when the rank is lower than num_topics requested
        attrs = [ContinuousVariable(n)
                 for n in self.topic_names[:n_topics]]

        t = Table.from_numpy(Domain(attrs, metas=[StringVariable('Word')]),
                             X=X, metas=np.array(sorted_words)[:, None])
        t.name = 'All topics'
        return t
开发者ID:s-alexey,项目名称:orange3-text,代码行数:22,代码来源:topics.py

示例12: received_table_load_votable

    def received_table_load_votable(self, private_key, sender_id, msg_id, mtype, parameters, extra):
        """
        Read the received VOTable and broadcast.
        """
        print("Call:", private_key, sender_id, msg_id, mtype, parameters, extra)

        # Retrieve and read the VOTable.
        url_table = parameters['url']

        # sys.stdout is redirected by canvas.__main__ via redirect_stdout()
        # in canvas.util.redirect to an
        # Orange.canvas.application.outputview.TextStream object. This
        # has a @queued_blocking flush(), which can result in an "Result not
        # yet ready" RuntimeError from the QueuedCallEvent class.
        # This exception is raised because astropy.io.votable.table uses
        # astropy.utils.xml.iterparser, which uses astropy.utils.data,
        # which uses the Spinner class from astropy.utils.console, which
        # finally uses stdout to output a progress indicator.
        # Orange has its own mechanisms for indicating progress, so it would
        # perhaps be better to try to use that.
        # For now, the Orange redirect of stdout is temporarily disabled
        # while the votable is being parsed.

        stdout_orange = sys.stdout
        sys.stdout = sys.__stdout__
        votable_tree = votable.parse(url_table)
        sys.stdout = stdout_orange

        print("VOTable Tree created")
        votable_table = votable_tree.get_first_table()
        #type(votable)
        #<class 'astropy.io.votable.tree.Table'>
        table = votable_table.to_table()
        #type(table)
        #<class 'astropy.table.table.Table'>
        print("AstroPy table made")



        # This does not allow classes.
        if False:
            # Convert the VOTable to a Domain.
            # TODO: Y en metas
            attributes = [
                ContinuousVariable(name=column)
                for column in table.columns
            ]
            domain = Domain(attributes = attributes)
            print("Domain made")

            # Convert the VOTable to a Table
            # Append the Table to LazyTable self.data.
            # (Re)send self.data).
            # TODO: Use from_domain() implicitly from __init__().
            # TODO: Include support to stop_pulling immediately.
            otable = Table.from_domain(
                #otable = LazyTable.from_domain(
                #otable = LazyTable(
                domain = domain,
                n_rows = len(table),
                #    stop_pulling = True,
            )
            otable.stop_pulling = True
            # TODO: set widget_origin?
            print("Orange Table initialized")
            for i, variable in enumerate(otable.domain.variables):
                otable.X[:,i] = table.columns[variable.name].data

        attributes = [
            ContinuousVariable(name=column)
            for column in table.columns if not 'CLASS' in column
        ]
        class_vars = [
            DiscreteVariable(name=column, values=['alpha', 'beta'])
            for column in table.columns if 'CLASS' in column
        ]
        domain = Domain(
            attributes=attributes,
            class_vars=class_vars,
        )

        otable = Table.from_domain(
            domain = domain,
            n_rows = len(table),
        )
        otable.stop_pulling = True
        print("Orange Table initialized")
        for i, variable in enumerate(otable.domain.attributes):
            otable.X[:,i] = table.columns[variable.name].data
        for i, variable in enumerate(otable.domain.class_vars):
            #otable.Y[:,i] = table.columns[variable.name].data
            #otable.Y[:] = table.columns[variable.name].data
            otable.Y[:] = table.columns[variable.name].data.round()

        print("Orange Table filled")
        if self.data is None:
            self.data = otable
        else:
            self.data.extend(otable)
            # TODO: Why doesn't this work?:
#.........这里部分代码省略.........
开发者ID:hugobuddel,项目名称:orange3,代码行数:101,代码来源:owsamp.py

示例13: open_file

    def open_file(self, fn):
        self.error()
        self.warning()
        self.information()
        fn_original = fn
        if not os.path.exists(fn):
            dir_name, basename = os.path.split(fn)
            if os.path.exists(os.path.join(".", basename)):
                fn = os.path.join(".", basename)
                self.information("Loading '{}' from the current directory."
                                 .format(basename))
        if fn == "(none)":
            self.send("Data", None)
            self.infoa.setText("No data loaded")
            self.infob.setText("")
            self.warnings.setText("")
            return

        self.loaded_file = ""

        data = None
        err_value = None
        try:
            # TODO handle self.new_variables
            data = Table(fn)
            self.loaded_file = fn
        except Exception as exc:
            err_value = str(exc)
            if "is being loaded as" in str(err_value):
                try:
                    data = Table(fn)
                    self.loaded_file = fn
                    self.warning(0, err_value)
                except:
                    data = None
        if err_value is not None:
            if fn.startswith("http"):
                err_value = "File '{}' does not contain valid data".format(
                    os.path.basename(fn)
                )
            ind = self.file_combo.currentIndex()
            text = self.file_combo.currentText()
            self.file_combo.removeItem(ind)
            self.file_combo.lineEdit().setText(text)
            if ind < len(self.recent_paths) and \
                            self.recent_paths[ind].abspath == fn_original:
                del self.recent_paths[ind]
            self.error(err_value)
            self.infoa.setText('Data was not loaded due to an error.')
            self.infob.setText('Error:')
            self.warnings.setText(err_value)

        if data is None:
            self.dataReport = None
        else:
            domain = data.domain
            self.infoa.setText(
                "{} instance(s), {} feature(s), {} meta attribute(s)"
                .format(len(data), len(domain.attributes), len(domain.metas)))
            if domain.has_continuous_class:
                self.infob.setText("Regression; numerical class.")
            elif domain.has_discrete_class:
                self.infob.setText("Classification; " +
                                   "discrete class with {} values."
                                   .format(len(domain.class_var.values)))
            elif data.domain.class_vars:
                self.infob.setText("Multi-target; {} target variables."
                                   .format(len(data.domain.class_vars)))
            else:
                self.infob.setText("Data has no target variable.")
            self.warnings.setText("")

            add_origin(data, fn)
            # make new data and send it
            file_name = os.path.split(fn)[1]
            if "." in file_name:
                data.name = file_name[:file_name.rfind('.')]
            else:
                data.name = file_name

            self.dataReport = self.prepareDataReport(data)
        self.send("Data", data)
开发者ID:PythonCharmers,项目名称:orange3,代码行数:82,代码来源:owfile.py

示例14: open_file

    def open_file(self, fn):
        self.error()
        self.warning()
        self.information()


        if not os.path.exists(fn):
            dirname, basename = os.path.split(fn)
            if os.path.exists(os.path.join(".", basename)):
                fn = os.path.join(".", basename)
                self.information("Loading '{}' from the current directory."
                                 .format(basename))
        if fn == "(none)":
            self.send("Data", None)
            self.infoa.setText("No data loaded")
            self.infob.setText("")
            self.warnings.setText("")
            return

        self.loaded_file = ""

        data = None
        try:
            # TODO handle self.new_variables
            data = Table(fn)
            self.loaded_file = fn
        except Exception as errValue:
            if "is being loaded as" in str(errValue):
                try:
                    data = Table(fn)
                    self.loaded_file = fn
                    self.warning(0, errValue)
                except:
                    self.error(errValue)
                    self.infoa.setText('Data was not loaded due to an error.')
                    self.infob.setText('Error:')
                    self.warnings.setText(errValue)

        if data is None:
            self.dataReport = None
        else:
            domain = data.domain
            self.infoa.setText(
                '{} instance(s), {} feature(s), {} meta attributes'
                .format(len(data), len(domain.attributes), len(domain.metas)))
            if isinstance(domain.class_var, ContinuousVariable):
                self.infob.setText('Regression; Numerical class.')
            elif isinstance(domain.class_var, DiscreteVariable):
                self.infob.setText('Classification; Discrete class with {} values.'
                                   .format(len(domain.class_var.values)))
            elif data.domain.class_vars:
                self.infob.setText('Multi-target; {} target variables.'
                                   .format(len(data.domain.class_vars)))
            else:
                self.infob.setText("Data has no target variable.")

            addOrigin(data, fn)
            # make new data and send it
            fName = os.path.split(fn)[1]
            if "." in fName:
                data.name = fName[:fName.rfind('.')]
            else:
                data.name = fName

            self.dataReport = self.prepareDataReport(data)
        self.send("Data", data)
开发者ID:fanfannothing,项目名称:orange3,代码行数:66,代码来源:owfile.py


注:本文中的Orange.data.table.Table类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。