Creating a new data table in Orange through Python



One of the first tasks in Orange data analysis is of course loading your data. If you are using Orange through Python, this is as easy as riding a bike:

import Orange
data =“iris”)
print (data)

This will return a neat data table of the famous Iris data set in the console.




What if you want to create your own data table from scratch? Even this is surprisingly simple. First, import the Orange data library.

from import *


Set all the attributes you wish to see in your data table. For discrete attributes call DiscreteVariable and set the name and the possible values, while for a continuous variable call ContinuousVariable and set only the attribute name.

color = DiscreteVariable(“color”, values=[“orange”, “green”, “yellow”])

calories = ContinuousVariable(“calories”)

fiber = ContinuousVariable(“fiber”)]

fruit = DiscreteVariable("fruit”, values=[”orange", “apple”, “peach”])


Then set the domain for your data table. See how we set class variable with class_vars?

domain = Domain([color, calories, fiber], class_vars=fruit)


Time to input your data!

data = Table(domain, [

[“green”, 4, 1.2, “apple”],

["orange", 5, 1.1, "orange"],

["yellow", 4, 1.0, "peach"]])


And now print what you have created!



One final step:, "")


Your data is safely stored to your computer (in the Python folder)! Good job!

  • Guan Ting Chen

    My Orange version is 3.1 realease. I follow this code. my “” content:

    color calories fiber fruit

    d c c d


    yellow -1.000 -1.000 peach

    yellow -1.000 -1.000 peach

    yellow -1.000 -1.000 peach

    • Kernc

      3.1 is pretty ancient. You should probably upgrade. 🙂

  • Joshua

    Thank you, this is a great intro.

    How would I import a CSV to an Orange Data Table directly through Python instead of the GUI?

    • Ajda Pretnar

      Dear Joshua,

      We are currently working on a new import model for Orange, CSV files included. We will post an update as soon as the changes are merged. Thank you for your patience. 🙂

    • Kernc

      In Orange3,

      from import Table
      data = Table('path/to/file.csv')