[SOLVED] String to number: parse(text) in Generate Attribute

PASEE
PASEE New Altair Community Member
edited November 5 in Community Q&A
Hello folks,

i have two attributes which are saved as polynomials/text. Now I want to parse them from text to numbers so i can make some calculations.

The attributes can look like this:
1.500,00
567,00
318,18

When I try to parse those to numbers RapidMiner tells me e.g. "String '567,00' is not a number."

Another problem is the dot in numbers bigger than 999, like 1.500,00.. In calculations RapidMiner takes this a a comma and thinks its "1,5" and not 1500.

How can i convert those numbers correctly?

Thank you very much!

Best regards,
PASEE

Answers

  • Nils_Woehler
    Nils_Woehler New Altair Community Member
    Hi,

    you can use "Parse numbers" with ',' as decimal character and '.' as grouping character.
    Have a look here:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.2.007">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="5.2.007" expanded="true" name="Process">
        <process expanded="true" height="370" width="820">
          <operator activated="true" class="text:create_document" compatibility="5.2.003" expanded="true" height="60" name="Create Document" width="90" x="45" y="75">
            <parameter key="text" value="1.500,00"/>
          </operator>
          <operator activated="true" class="text:create_document" compatibility="5.2.003" expanded="true" height="60" name="Create Document (2)" width="90" x="45" y="165">
            <parameter key="text" value="567,00"/>
          </operator>
          <operator activated="true" class="text:create_document" compatibility="5.2.003" expanded="true" height="60" name="Create Document (3)" width="90" x="45" y="255">
            <parameter key="text" value="318,18"/>
          </operator>
          <operator activated="true" class="text:documents_to_data" compatibility="5.2.003" expanded="true" height="112" name="Documents to Data" width="90" x="313" y="120">
            <parameter key="text_attribute" value="numbers"/>
          </operator>
          <operator activated="true" class="text_to_nominal" compatibility="5.2.007" expanded="true" height="76" name="Text to Nominal" width="90" x="514" y="120"/>
          <operator activated="true" class="parse_numbers" compatibility="5.2.007" expanded="true" height="76" name="Parse Numbers" width="90" x="648" y="120">
            <parameter key="attribute" value="numbers"/>
            <parameter key="decimal_character" value=","/>
            <parameter key="grouped_digits" value="true"/>
            <parameter key="grouping_character" value="."/>
          </operator>
          <connect from_op="Create Document" from_port="output" to_op="Documents to Data" to_port="documents 1"/>
          <connect from_op="Create Document (2)" from_port="output" to_op="Documents to Data" to_port="documents 2"/>
          <connect from_op="Create Document (3)" from_port="output" to_op="Documents to Data" to_port="documents 3"/>
          <connect from_op="Documents to Data" from_port="example set" to_op="Text to Nominal" to_port="example set input"/>
          <connect from_op="Text to Nominal" from_port="example set output" to_op="Parse Numbers" to_port="example set input"/>
          <connect from_op="Parse Numbers" from_port="example set output" to_port="result 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
        </process>
      </operator>
    </process>
    Best,
    Nils
  • PASEE
    PASEE New Altair Community Member
    sorry, but I have no idea what to do with this code? import it to rapidminer or something?

    thank you
  • Nils_Woehler
    Nils_Woehler New Altair Community Member
  • PASEE
    PASEE New Altair Community Member
    vielen dank für den hinweis und die hilfe,
    mein problem ist damit gelöst!