How to insert text in multiple attributes (in the beginning)?

ebayundsoebayundso Member Posts: 2 Contributor I
edited August 2019 in Help

Hi all,

i try to add text to all my values in one attrtibute, for example my values of attributes are:

 

Up

Polo

Beetle

Tiguan
Touran

Caddy
Golf

Passat

 

an they should add "VW" in the beginning:

 

VW Up

VW Polo

VW Beetle

VW Tiguan
VW Touran

VW Caddy
VW Golf

VW Passat

 

Do you have a solution for my problem? :)

Answers

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,761 Unicorn

    I would use the Replace operator for that. You'd have to do a RegEx to select the word and then append it with VW.

     

    of the top of my head something like this (.*) to select it and replace it with VW $1

  • lionelderkrikorlionelderkrikor Moderator, RapidMiner Certified Analyst, Member Posts: 1,195 Unicorn

    Hi @ebayundso,

     

    I don't know if it is the optimal solution, but it works : 

    <?xml version="1.0" encoding="UTF-8"?><process version="8.1.003">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="8.1.003" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="read_excel" compatibility="8.1.003" expanded="true" height="68" name="Read Excel" width="90" x="179" y="34">
    <parameter key="excel_file" value="C:\Users\Lionel\Documents\Formations_DataScience\Rapidminer\Tests_Rapidminer\Replace_Values\Replace_values.xlsx"/>
    <parameter key="imported_cell_range" value="A1:A9"/>
    <parameter key="first_row_as_names" value="false"/>
    <list key="annotations">
    <parameter key="0" value="Name"/>
    </list>
    <list key="data_set_meta_data_information">
    <parameter key="0" value="Att1.true.polynominal.attribute"/>
    </list>
    </operator>
    <operator activated="true" class="replace" compatibility="8.1.003" expanded="true" height="82" name="Replace" width="90" x="313" y="34">
    <parameter key="attribute_filter_type" value="single"/>
    <parameter key="attribute" value="Att1"/>
    <parameter key="replace_what" value="(?&lt;![^ ])(?=[^ ])(?!VW )"/>
    <parameter key="replace_by" value="\VW "/>
    </operator>
    <connect from_op="Read Excel" from_port="output" to_op="Replace" to_port="example set input"/>
    <connect from_op="Replace" 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>

    Regards,

     

    Lionel

  • ebayundsoebayundso Member Posts: 2 Contributor I

    Thomas_Ottthis adds a "VW" in the beginning but also in the end... :(

  • Telcontar120Telcontar120 Moderator, RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,635 Unicorn

    Using "Generate Attributes" you can also create another attribute with the value VW (or other car manufacturers as needed) and then create a third attribute which concatenates the manufacturer and the model.

     

    Brian T.
    Lindon Ventures 
    Data Science Consulting from Certified RapidMiner Experts
  • Edin_KlapicEdin_Klapic Moderator, Employee, RMResearcher, Member Posts: 299 RM Data Scientist

    Hi @ebayundso,

     

    In the Parameter replace what the RegEx characters ^ and $ have an additional meaning.

    If you use ^ as first character it means "Beginning". $ means "End"

    The RegEx would then be:

    Replace: ^(.*)$

    by: VW $1

     

    Happy Mining,

    Edin

Sign In or Register to comment.