RapidMiner

Change value order?

SOLVED
Super Contributor

Change value order?

Hey altogether,

 

simple problem with hopefully a simple answer. Is there a way (in excel this is quite easy) to change orders withing an example e.g.

12.25.23 to 25.12.23

Thank you for your help.

10 REPLIES
Moderator

Re: Change value order?

Hey,

 

do you mean attribute order? If yes, reorder attributes is the operator. Or do you to sort a string?

 

~Martin

--------------------------------------------------------------------------
Head of Data Science Services at RapidMiner
Super Contributor

Re: Change value order?

No, I don't want to change the order. In Excel you would use the mid() function the reorder Parts of one "cell".
Highlighted
Moderator

Re: Change value order?

[ Edited ]

Hey,

 

you can go for a Replace operator with a regex

 

(\d+).(\d+).(\d+)

 

and replace it with

 

$2.$1.$3

 

Edit: I think the Excel mid is similar than cut() in Generate Attributes, if you prefer this.

 

Best,

Martin

--------------------------------------------------------------------------
Head of Data Science Services at RapidMiner
Super Contributor

Re: Change value order?

Regex worked pretty well. Going a step further what I wanted to achieve was to convert the english date into a german one so:

12/3/16 (mm/dd/yy) in 03.12.16

I replaced the "/" with dots and changed the order of day and month with the regex-replace. Now to further work with this date in excel it should be in the named format (above). Unfortunately it is in the format 3.12.16, thus the zeros are missing. 

My question is how can I get the zeros in the date and if this way of achieving this is even good to do so, because I think this is somehow very complicated to just transform english date into a german one.

Thank you 

Philipp

Moderator

Re: Change value order?

Hey,

 

i think its just another regex with Replace:

 

0(\d)

 

replace with

 

$1


Attached is a process doing it.

 

~Martin

<?xml version="1.0" encoding="UTF-8"?><process version="7.4.000">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="7.4.000" expanded="true" name="Process">
    <process expanded="true">
      <operator activated="true" class="generate_data_user_specification" compatibility="7.4.000" expanded="true" height="68" name="Generate Data by User Specification" width="90" x="112" y="34">
        <list key="attribute_values">
          <parameter key="date" value="&quot;03.12.16&quot;"/>
        </list>
        <list key="set_additional_roles"/>
      </operator>
      <operator activated="true" class="replace" compatibility="7.4.000" expanded="true" height="82" name="Replace" width="90" x="246" y="34">
        <parameter key="replace_what" value="(\d+).(\d+).(\d+)"/>
        <parameter key="replace_by" value="$2.$1.$3"/>
      </operator>
      <operator activated="true" class="replace" compatibility="7.4.000" expanded="true" height="82" name="Replace (2)" width="90" x="380" y="34">
        <parameter key="replace_what" value="0(\d)"/>
        <parameter key="replace_by" value="$1"/>
      </operator>
      <connect from_op="Generate Data by User Specification" from_port="output" to_op="Replace" to_port="example set input"/>
      <connect from_op="Replace" from_port="example set output" to_op="Replace (2)" to_port="example set input"/>
      <connect from_op="Replace (2)" 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>
--------------------------------------------------------------------------
Head of Data Science Services at RapidMiner
RMStaff

Re: Change value order?

Hi Philipp,

 

I suggest the usage of the Generate Attributes Operator and the built-in date conversion functions.

The following expression converts the nominal value "12/3/16" into the desired nominal output format "03.12.16".

 

date_str_custom(date_parse_custom("12/3/16","M/d/yy"),"dd.MM.yy")

 

Simply replace the string with the attribute name and you are set Smiley Happy

 

Best regards,

Edin

Super Contributor

Re: Change value order?

But then he "deletes" the zeros? I tried it and nothing really changed. The process you posted unfortunately doesn't work. It says "Day not found".

RMStaff

Re: Change value order?

Although I am sure that you will get there with regex I think Edin's solution above is the simplest approach...


How to load processes in XML from the forum into RapidMiner: Read this!
Super Contributor

Re: Change value order?

Thank you Edin, 

that soundy very useful. When I replace the string (name of the attribute is "Day")

date_str_custom(date_parse_custom("Day","M/d/yy"),"dd.MM.yy")

I get the error: "invalid_argument.date." and the process stops.

Do you know where there could be a mistake?

Philipp