Rename many columns

choose_username
choose_username New Altair Community Member
edited November 5 in Community Q&A
Hi there,

i wanted to rename a column with the Operator Rename. The Problem is that i have to rename 31 columns. As far as i see i do need to use 31 Rename-Operators? My Question is: Is there a way to rename all 31 columns with 1 operator?


thanks in advance

user
Tagged:

Answers

  • wessel
    wessel New Altair Community Member
    Use the Loop Attributes operator?

  • IngoRM
    IngoRM New Altair Community Member
    Hi,

    maybe the operators "Rename by Replacing" or "Rename by Generic Names" can also be helpful. If you want to use specific names, looping could indeed be the best option - you could even take the old and new names from another example set...

    Cheers,
    Ingo
  • choose_username
    choose_username New Altair Community Member
    Hello,

    the approach with the Loop sounds interessting. By trying it i found out that it is neccessary to make use of macros. Is there a tutorial or example how to do this in RM?


    (btw its a great product with great support)


    Greetings

    User
  • IngoRM
    IngoRM New Altair Community Member
    Hi,

    did you try our new Community Extension? Just download and install it from our update- and installation server via the Help menu of RapidMiner. You can search for processes containing the word "Loop" or "Macro" and you will see several examples of processes containing operators making use of them.

    Cheers,
    Ingo
  • If you want a quick and dirty hack, I successfully used the de-obfuscate operator to rename columns. Provide an obfuscation map file containing a row for each attribute you want to rename in the following form:

    oldname<tab>newname
    The tab is important; spaces cause an error.

    Ugly but effective.

    regards,

    Andrew
  • IngoRM
    IngoRM New Altair Community Member
    Nice one  ;)

    Cheers,
    Ingo
  • choose_username
    choose_username New Altair Community Member
    thx for the tip. i will give it a try : )

    greetings User
  • wessel
    wessel New Altair Community Member
    How to convert all attributes to lower-case?
  • choose_username
    choose_username New Altair Community Member
    well i simply use the Rename Operator. But maybe there s a solution tryin "Rename by Replacing" in combination with an regular expression like  [A-Z]  ->  [a-z] and a loop or smthing

    greetings

    User
  • wessel
    wessel New Altair Community Member
    hmm :P

    Then you need to type 26 replacements..
  • IngoRM
    IngoRM New Altair Community Member
    Hi,

    this is easily possible with a short script. You can find an example process with our Community Extension for RapidMiner. Just download the extension, show the corresponding view and search for the process "Transform Attribute Names to lower Case (Script)". You can then simply download the process and run it directly in your client.

    Cheers,
    Ingo
  • wessel
    wessel New Altair Community Member
    awchisholm wrote:

    If you want a quick and dirty hack, I successfully used the de-obfuscate operator to rename columns. Provide an obfuscation map file containing a row for each attribute you want to rename in the following form:

    oldname<tab>newname
    The tab is important; spaces cause an error.

    Ugly but effective.

    regards,

    Andrew
    How does this work?
  • Here's an example process

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.0">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" expanded="true" name="Process">
        <process expanded="true" height="161" width="480">
          <operator activated="true" class="generate_data" expanded="true" height="60" name="Generate Data" width="90" x="112" y="75"/>
          <operator activated="true" class="de_obfuscate" expanded="true" height="76" name="rename" width="90" x="380" y="75">
            <parameter key="obfuscation_map_file" value="c:\temp\att.txt"/>
          </operator>
          <connect from_op="Generate Data" from_port="output" to_op="rename" to_port="example set input"/>
          <connect from_op="rename" 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>


    The file referred to is here

    att1 apple
    att2 banana
    att3 pear
    att4 grape
    att5 orange
    Ugly but effective

    Andrew