The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
rename many similar attribute
hi there. i have so many attributes that named "att_1, att_2, ..., att_500". i want to rename them to eg "attribute". how can i do that? Thanks
Tagged:
0
Best Answer
-
CKönig Employee-RapidMiner, Member Posts: 70 RM Team MemberHi @Sadegh95
You are most likely looking for the De-Pivot operator:
Here is the example process I created showing you both the preferred De-Pivot version as well as a manual version making use of Loop Attributes that you were asking for originally. Please remember, that looping over data is usually much slower than specialized operators.<?xml version="1.0" encoding="UTF-8"?><process version="10.2.000"> <context> <input/> <output/> <macros/> </context> <operator activated="true" class="process" compatibility="10.2.000" expanded="true" name="Process"> <parameter key="logverbosity" value="init"/> <parameter key="random_seed" value="2001"/> <parameter key="send_mail" value="never"/> <parameter key="notification_email" value=""/> <parameter key="process_duration_for_mail" value="30"/> <parameter key="encoding" value="SYSTEM"/> <process expanded="true"> <operator activated="true" breakpoints="after" class="subprocess" compatibility="10.2.000" expanded="true" height="82" name="Subprocess" width="90" x="45" y="34"> <process expanded="true"> <operator activated="true" class="retrieve" compatibility="10.2.000" expanded="true" height="68" name="Retrieve Iris" width="90" x="45" y="34"> <parameter key="repository_entry" value="//Samples/data/Iris"/> </operator> <operator activated="true" class="blending:select_attributes" compatibility="10.2.000" expanded="true" height="82" name="Select Attributes" width="90" x="179" y="34"> <parameter key="type" value="exclude attributes"/> <parameter key="attribute_filter_type" value="one attribute"/> <parameter key="select_attribute" value="label"/> <parameter key="select_subset" value="id␞label"/> <parameter key="also_apply_to_special_attributes_(id,_label..)" value="true"/> </operator> <operator activated="true" class="rename_by_replacing" compatibility="10.2.000" expanded="true" height="82" name="Rename by Replacing" width="90" x="313" y="34"> <parameter key="attribute_filter_type" value="regular_expression"/> <parameter key="attribute" value=""/> <parameter key="attributes" value=""/> <parameter key="regular_expression" value="a[0-9]"/> <parameter key="use_except_expression" value="false"/> <parameter key="value_type" value="attribute_value"/> <parameter key="use_value_type_exception" value="false"/> <parameter key="except_value_type" value="time"/> <parameter key="block_type" value="attribute_block"/> <parameter key="use_block_type_exception" value="false"/> <parameter key="except_block_type" value="value_matrix_row_start"/> <parameter key="invert_selection" value="false"/> <parameter key="include_special_attributes" value="false"/> <parameter key="replace_what" value="a([0-9])"/> <parameter key="replace_by" value="Person$1"/> </operator> <connect from_op="Retrieve Iris" from_port="output" to_op="Select Attributes" to_port="example set input"/> <connect from_op="Select Attributes" from_port="example set output" to_op="Rename by Replacing" to_port="example set input"/> <connect from_op="Rename by Replacing" from_port="example set output" to_port="out 1"/> <portSpacing port="source_in 1" spacing="0"/> <portSpacing port="sink_out 1" spacing="0"/> <portSpacing port="sink_out 2" spacing="0"/> </process> <description align="center" color="transparent" colored="false" width="126">generate example data</description> </operator> <operator activated="true" class="multiply" compatibility="10.2.000" expanded="true" height="103" name="Multiply" width="90" x="179" y="34"/> <operator activated="true" class="de_pivot" compatibility="10.2.000" expanded="true" height="82" name="De-Pivot" width="90" x="380" y="34"> <list key="attribute_name"> <parameter key="Person" value="Person[0-9]*"/> </list> <parameter key="index_attribute" value="OriginalName"/> <parameter key="create_nominal_index" value="true"/> <parameter key="keep_missings" value="false"/> <description align="center" color="transparent" colored="false" width="126">Transform a wide ExampleSet with multiple Attributes measuring the same thing into a long ExampleSet with one Attribute</description> </operator> <operator activated="true" class="concurrency:loop_attributes" compatibility="10.2.000" expanded="true" height="82" name="Loop Attributes" width="90" x="313" y="340"> <parameter key="attribute_filter_type" value="regular_expression"/> <parameter key="attribute" value=""/> <parameter key="attributes" value=""/> <parameter key="regular_expression" value="Person[0-9]*"/> <parameter key="use_except_expression" value="false"/> <parameter key="value_type" value="attribute_value"/> <parameter key="use_value_type_exception" value="false"/> <parameter key="except_value_type" value="time"/> <parameter key="block_type" value="attribute_block"/> <parameter key="use_block_type_exception" value="false"/> <parameter key="except_block_type" value="value_matrix_row_start"/> <parameter key="invert_selection" value="false"/> <parameter key="include_special_attributes" value="false"/> <parameter key="attribute_name_macro" value="loop_attribute"/> <parameter key="reuse_results" value="false"/> <parameter key="enable_parallel_execution" value="true"/> <process expanded="true"> <operator activated="true" class="blending:select_attributes" compatibility="10.2.000" expanded="true" height="82" name="Select Attributes (3)" width="90" x="179" y="34"> <parameter key="type" value="include attributes"/> <parameter key="attribute_filter_type" value="one attribute"/> <parameter key="select_attribute" value="%{loop_attribute}"/> <parameter key="select_subset" value=""/> <parameter key="also_apply_to_special_attributes_(id,_label..)" value="false"/> <description align="center" color="transparent" colored="false" width="126">only keep the current attribute</description> </operator> <operator activated="true" class="blending:rename" compatibility="10.2.000" expanded="true" height="82" name="Rename" width="90" x="313" y="34"> <list key="rename attributes"> <parameter key="%{loop_attribute}" value="Person"/> </list> <parameter key="from_attribute" value=""/> <parameter key="to_attribute" value=""/> <description align="center" color="transparent" colored="false" width="126">rename it to &quot;Person&quot;</description> </operator> <connect from_port="input 1" to_op="Select Attributes (3)" to_port="example set input"/> <connect from_op="Select Attributes (3)" from_port="example set output" to_op="Rename" to_port="example set input"/> <connect from_op="Rename" from_port="example set output" to_port="output 1"/> <portSpacing port="source_input 1" spacing="0"/> <portSpacing port="source_input 2" spacing="0"/> <portSpacing port="sink_output 1" spacing="0"/> <portSpacing port="sink_output 2" spacing="0"/> <description align="center" color="yellow" colored="false" height="105" resized="false" width="113" x="28" y="69">The complete ExampleSet is delivered at the input port</description> </process> <description align="center" color="transparent" colored="false" width="126">Loop over all &quot;Person&quot; attributes<br/><br/>the current attribute name is stored in a macro</description> </operator> <operator activated="true" class="append" compatibility="10.2.000" expanded="true" height="82" name="Append" width="90" x="581" y="340"> <parameter key="datamanagement" value="double_array"/> <parameter key="data_management" value="auto"/> <parameter key="merge_type" value="all"/> <description align="center" color="transparent" colored="false" width="126">flatten the collection by appending everything<br/><br/>This works, because all ExampleSets have the same shape</description> </operator> <connect from_op="Subprocess" from_port="out 1" to_op="Multiply" to_port="input"/> <connect from_op="Multiply" from_port="output 1" to_op="De-Pivot" to_port="example set input"/> <connect from_op="Multiply" from_port="output 2" to_op="Loop Attributes" to_port="input 1"/> <connect from_op="De-Pivot" from_port="example set output" to_port="result 1"/> <connect from_op="Loop Attributes" from_port="output 1" to_op="Append" to_port="example set 1"/> <connect from_op="Append" from_port="merged set" to_port="result 2"/> <portSpacing port="source_input 1" spacing="0"/> <portSpacing port="sink_result 1" spacing="0"/> <portSpacing port="sink_result 2" spacing="231"/> <portSpacing port="sink_result 3" spacing="0"/> <description align="center" color="yellow" colored="false" height="143" resized="false" width="141" x="423" y="384">Result will be a collection of individual ExampleSets each containing one original &quot;column&quot; renamed to Person</description> <description align="center" color="yellow" colored="false" height="132" resized="true" width="290" x="674" y="96">Both ExampleSets will contain the same values, but in a different order:<br/><br/>De-Pivot works row-wise<br/><br/>Loop Attributes works column-wise</description> </process> </operator> </process>
Hope this helps!
Kind regards,
Christian1
Answers
Dortmund, Germany
Dortmund, Germany
If so:
Dortmund, Germany
as Martin already mentioned: all Attribute (column) names must be unique, duplicate names are not allowed.
May I ask, why you would want to do that? If the data in those colums indeed represents the same thing, you could think about de-pivoting to create multiple Examples (rows) out of them. You can have a look at the tutorial process for the "De-Pivot" operator to see an example.