How to calculate the attribute and replace the number and letter to the calculated value in rapidmi.

jabr
jabr New Altair Community Member
edited November 5 in Community Q&A
In the dataset, we have an attribute size that contains the size of the app like 12M, 45K, etc. I would like to calculate the 12M as 12*1000000 and replace the value as 12000000 and for 45K as 45*1000 and replace the value as 45000.
I have added a map operator and given the regular expression. But it not calculating in the Rapid miner. Please help  

Best Answers

  • Caperez
    Caperez Altair Community Member
    Answer ✓
    Hi @jabr

    please find attached an example to convert it. 

    Best
  • lionelderkrikor
    lionelderkrikor New Altair Community Member
    Answer ✓
    Hi @jabr,

    In attached file, you can find a working process which performs the requested transformation. (....inspired by @ceaperez solution ... ;)

    The trick here is to : 
     - replace "M" by "*1000000" (and "k" by "*1000")
     - split (using the Split operator) based on the caracter "*" pattern which produce 2 new attributes (size_1 and size_2)
    - generate the requested attribute (New size) by multiplying "size_1 by "size_2"

    You can remove the intermediate attributes  (Size_1 and Size_2) by adding and selecting these 2 attributes in the Select Attributes operator.

    Hope this helps,

    Regards,

    Lionel 


Answers

  • Caperez
    Caperez Altair Community Member
    Hi @jabr
    One way is to use Replace Operator to remove the k character using a regular expression [k]. Then you can use the Parse Numbers Operator to transform the polynominal attribute to numeric. Withe the numerical attribute you can create a new one with a simple calculation

    Best
  • jabr
    jabr New Altair Community Member
    Thanks, @ceaperez for the solution. I can replace the K character. But if I remove the character then I won't be able to calculate it. All sizes 12M, 14K are given together in one column. If it is M then the number should be multiplied by 1000000 and if it is K then the number should be multiplied by 1000.  
  • Caperez
    Caperez Altair Community Member
    Answer ✓
    Hi @jabr

    please find attached an example to convert it. 

    Best
  • lionelderkrikor
    lionelderkrikor New Altair Community Member
    Answer ✓
    Hi @jabr,

    In attached file, you can find a working process which performs the requested transformation. (....inspired by @ceaperez solution ... ;)

    The trick here is to : 
     - replace "M" by "*1000000" (and "k" by "*1000")
     - split (using the Split operator) based on the caracter "*" pattern which produce 2 new attributes (size_1 and size_2)
    - generate the requested attribute (New size) by multiplying "size_1 by "size_2"

    You can remove the intermediate attributes  (Size_1 and Size_2) by adding and selecting these 2 attributes in the Select Attributes operator.

    Hope this helps,

    Regards,

    Lionel 


  • jabr
    jabr New Altair Community Member
    Hi @ceaperez

    Thanks a million. It is working perfectly
  • jabr
    jabr New Altair Community Member
    @lionelderkrikor Thanks a million :smile: