Simple Python Script for transforming Table features

I'm currently setting up a very basic Cheminformatics pipeline for use within my academic research group to help us filter through commercially available compounds. I am a beginner KNIME user, but have a decent enough understanding of Python to think I might be able to use it to help with my issue.

I have a Table in which chemical compounds have a number of different features, three of which are important - one for $QuantityNumber$ i.e 250; one for $Unit$ i.e. grams; and one for $Price$ i.e. 104.

However, I want to later perform a calculation where I can work out price per gram, and some of the quantities are in milligrams - for this reason, I want to alter the price depending on the unit.

Could somebody please walk me through how to setup a Python scripting node in which I can do something like this for each entry in the Table (in this example converting a price and weight combination in milligrams to the appropriate price in grams) :

if $Unit$ = 'mg':

    QuantityFactor = 1000 / $QuantityNumber$ (to find factor by which to multiply to get price for one gram of material)

    $QuantityNumber$ = 1 (to set the quantity to 1 gram for the calculation)

    $Price$ = $Price$ * QuantityFactor (to get the price per gram)

 

Thanks in advance.

 

Hi Jaxx,

Thank you for contacting KNIME with your questions. 

From our point of view this case could be solved without any python scripting.

To keep the important features in your data table, you could use Column Filter node. Please check this post as an example.

To convert the prices check out Math Formula node. 

I hope it helps to steer you in the right direction. However, if it doesn't, could you provide an example data file (e.g. 10-20 lines) to illustrate the problem? 

As a final bit of help I would point you to the upcoming training course in Berlin where you would have a great opportunity to learn the Analytics platform

 

Best, Daria