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
Concatenate Two Numbers
I have two attributes Year (ex. 2016) and month (1) both are numerical. I need to generate an attribute that will create (20161) and keep the attribute as numerical.
Generate concatenation operator has .0 and "_" that I can't get rid off.
Generate attribute with concat() function doesn't like that those are numerical and not strings.
Any suggestions?
Help is much appreciated.
Generate concatenation operator has .0 and "_" that I can't get rid off.
Generate attribute with concat() function doesn't like that those are numerical and not strings.
Any suggestions?
Help is much appreciated.
0
Best Answers
-
varunm1 Member Posts: 1,207 UnicornHello @asav_yu
I selected _ as a separator in the generate concatenation operator. Then I attached a replace operator where it will replace _ with nothing in the new attribute. The sample code below.<?xml version="1.0" encoding="UTF-8"?><process version="9.2.001"> <context> <input/> <output/> <macros/> </context> <operator activated="true" class="process" compatibility="6.0.002" expanded="true" name="Process" origin="GENERATED_TUTORIAL"> <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" class="retrieve" compatibility="9.2.001" expanded="true" height="68" name="Labor-Negotiations" origin="GENERATED_TUTORIAL" width="90" x="179" y="120"> <parameter key="repository_entry" value="//Samples/data/Labor-Negotiations"/> </operator> <operator activated="true" class="generate_concatenation" compatibility="9.2.001" expanded="true" height="82" name="Generate Concatenation" origin="GENERATED_TUTORIAL" width="90" x="380" y="120"> <parameter key="first_attribute" value="vacation"/> <parameter key="second_attribute" value="statutory-holidays"/> <parameter key="separator" value="_"/> <parameter key="trim_values" value="false"/> </operator> <operator activated="true" class="replace" compatibility="9.2.001" expanded="true" height="82" name="Replace" width="90" x="581" y="85"> <parameter key="attribute_filter_type" value="single"/> <parameter key="attribute" value="vacation_statutory-holidays"/> <parameter key="attributes" value=""/> <parameter key="use_except_expression" value="false"/> <parameter key="value_type" value="nominal"/> <parameter key="use_value_type_exception" value="false"/> <parameter key="except_value_type" value="file_path"/> <parameter key="block_type" value="single_value"/> <parameter key="use_block_type_exception" value="false"/> <parameter key="except_block_type" value="single_value"/> <parameter key="invert_selection" value="false"/> <parameter key="include_special_attributes" value="false"/> <parameter key="replace_what" value="_"/> </operator> <connect from_op="Labor-Negotiations" from_port="output" to_op="Generate Concatenation" to_port="example set input"/> <connect from_op="Generate Concatenation" from_port="example set 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="90"/> <portSpacing port="sink_result 2" spacing="0"/> </process> </operator> </process>
This works now. There might be better solutions.Regards,
Varun
https://www.varunmandalapu.com/Be Safe. Follow precautions and Maintain Social Distancing
7 -
yyhuang Administrator, Employee-RapidMiner, RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 364 RM Data ScientistHi @asav_yu,
Usually, the month could be single digit or double digits. So I personally prefer to concatenate the year, possible "0", and month in the generate attribute operator.
Because it would be consistently neat looking if you have 201601, 201612, .... rather than 20161, 201612. My output looks like this
process<?xml version="1.0" encoding="UTF-8"?><process version="9.2.001"> <context> <input/> <output/> <macros/> </context> <operator activated="true" class="process" compatibility="6.0.002" expanded="true" name="Process" origin="GENERATED_TUTORIAL"> <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" class="generate_sales_data" compatibility="9.2.001" expanded="true" height="68" name="Generate Sales Data" width="90" x="246" y="34"> <parameter key="number_examples" value="100"/> <parameter key="use_local_random_seed" value="false"/> <parameter key="local_random_seed" value="1992"/> </operator> <operator activated="true" class="date_to_numerical" compatibility="9.2.001" expanded="true" height="82" name="Date to Numerical" width="90" x="380" y="34"> <parameter key="attribute_name" value="date"/> <parameter key="time_unit" value="year"/> <parameter key="millisecond_relative_to" value="second"/> <parameter key="second_relative_to" value="minute"/> <parameter key="minute_relative_to" value="hour"/> <parameter key="hour_relative_to" value="day"/> <parameter key="day_relative_to" value="month"/> <parameter key="week_relative_to" value="year"/> <parameter key="month_relative_to" value="year"/> <parameter key="quarter_relative_to" value="year"/> <parameter key="half_year_relative_to" value="year"/> <parameter key="year_relative_to" value="era"/> <parameter key="keep_old_attribute" value="true"/> <description align="center" color="transparent" colored="false" width="126">get year</description> </operator> <operator activated="true" class="date_to_numerical" compatibility="9.2.001" expanded="true" height="82" name="Date to Numerical (2)" width="90" x="514" y="34"> <parameter key="attribute_name" value="date"/> <parameter key="time_unit" value="month"/> <parameter key="millisecond_relative_to" value="second"/> <parameter key="second_relative_to" value="minute"/> <parameter key="minute_relative_to" value="hour"/> <parameter key="hour_relative_to" value="day"/> <parameter key="day_relative_to" value="month"/> <parameter key="week_relative_to" value="year"/> <parameter key="month_relative_to" value="year"/> <parameter key="quarter_relative_to" value="year"/> <parameter key="half_year_relative_to" value="year"/> <parameter key="year_relative_to" value="era"/> <parameter key="keep_old_attribute" value="true"/> <description align="center" color="transparent" colored="false" width="126">get month</description> </operator> <operator activated="true" class="select_attributes" compatibility="9.2.001" expanded="true" height="82" name="Select Attributes" width="90" x="648" y="34"> <parameter key="attribute_filter_type" value="subset"/> <parameter key="attribute" value=""/> <parameter key="attributes" value="date|date_year|date_month"/> <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"/> </operator> <operator activated="true" class="generate_attributes" compatibility="9.2.001" expanded="true" height="82" name="Generate Attributes" width="90" x="782" y="34"> <list key="function_descriptions"> <parameter key="New_YearMo" value="concat(str(date_year),suffix(concat("0",str(date_month)),2))"/> </list> <parameter key="keep_all" value="true"/> <description align="center" color="transparent" colored="false" width="126">concatenate year and month</description> </operator> <operator activated="true" class="parse_numbers" compatibility="9.2.001" expanded="true" height="82" name="Parse Numbers" width="90" x="916" y="34"> <parameter key="attribute_filter_type" value="all"/> <parameter key="attribute" value=""/> <parameter key="attributes" value=""/> <parameter key="use_except_expression" value="false"/> <parameter key="value_type" value="nominal"/> <parameter key="use_value_type_exception" value="false"/> <parameter key="except_value_type" value="file_path"/> <parameter key="block_type" value="single_value"/> <parameter key="use_block_type_exception" value="false"/> <parameter key="except_block_type" value="single_value"/> <parameter key="invert_selection" value="false"/> <parameter key="include_special_attributes" value="false"/> <parameter key="decimal_character" value="."/> <parameter key="grouped_digits" value="false"/> <parameter key="grouping_character" value=","/> <parameter key="infinity_representation" value=""/> <parameter key="unparsable_value_handling" value="fail"/> <description align="center" color="transparent" colored="false" width="126">convert nominal to numerical</description> </operator> <connect from_op="Generate Sales Data" from_port="output" to_op="Date to Numerical" to_port="example set input"/> <connect from_op="Date to Numerical" from_port="example set output" to_op="Date to Numerical (2)" to_port="example set input"/> <connect from_op="Date to Numerical (2)" from_port="example set output" to_op="Select Attributes" to_port="example set input"/> <connect from_op="Select Attributes" from_port="example set output" to_op="Generate Attributes" to_port="example set input"/> <connect from_op="Generate Attributes" 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="90"/> <portSpacing port="sink_result 2" spacing="0"/> </process> </operator> </process>
7 -
Telcontar120 RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,635 UnicornIF you are ok having the resulting field be a numerical instead of nominal, you don't need to concatenate at all. Just use Generate Attributes to multiply the year by 100, and then add the month number. So you get 201901, 201902, ...201912. Like @yyhuang's format, only as a numerical. This is the way I usually prefer to handle this type of year and month combination.9
Answers