2
$\begingroup$

This is a fairly basic question. How do you create a new column in Orange - based upon an existing column?

For example:

NewCol = 2 * ExistingColumn

or

NewCol = len(ExistingColumn)

I would like to use the Python Script Widget - not the feature widget.

$\endgroup$
0
$\begingroup$

You'd think it would be basic. So far I'm not finding it to be so. Here's one example that worked for me. I'm sure it can be much simpler.:

from Orange.data import ContinuousVariable, DiscreteVariable, Domain

out_data = in_data.copy()
var1 = ContinuousVariable("NewCol")
domain = out_data.domain
new_domain = Domain(attributes=domain.attributes + (var1,), metas=domain.metas, class_vars=domain.class_vars)
out_data = out_data.transform(new_domain)

i2 = out_data.domain.index(out_data.domain["NewCol"])
i1 = out_data.domain.index(out_data.domain["ExistingColumn"])
out_data.X[:, i2] = out_data.X[:,i1] * 2
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.