Orange Forum • View topic - load multliple files into orange

load multliple files into orange

A place to ask questions about methods in Orange and how they are used and other general support.

load multliple files into orange

Postby Guest2 » Thu Mar 26, 2009 19:32

Hi,

I have about 50 different files and I want to execute same code for each of them. Is it possible to create a loop that will have 50 iterations and will read one file at a time?
So far, I have created a file with the path.filename of all 50 files.
In python, I created a loop that reads these names and store it in the variable.
Then, I tried to load the file into python using orange.ExampleTable(variable). However, when I execute the code, it gives me an error.
Here is the code:
data = orange.ExampleTable("path.filename")
for i in range (len(data)):
domain = data[i]
#after execution domain = 'path.filename'
train = orange.ExampleTable(domain)

Any help will be much appreciated!

Postby bgbg » Fri Mar 27, 2009 17:34

Please use code formatting for pasting program code. This is especially important for whitespace-sensitive languages such as Python.

Also, you said that executing the code gave you an error. Usually, it is much easier to help if you specify which error you receive.

Anyhow, try the following:

Code: Select all
import orange
lFiles = [ 'file1.tab', 'file2.tab', 'file3.tab']
doInitializationStuff()
for strFileData in lFiles:
    data = orange.ExampleTable(strFileData)

    doThisThatAndTheOther(data)
   
    # empty the domain classVar values
    # see http://www.ailab.si/orange/forum/viewtopic.php?t=672
    data.domain.classVar.values = []
doFinalizationStuff()


Return to Questions & Support