For Loop for Moving Data to New ColumnsIs there an easier way, possibly with a For loop, to get data from multiple "cells" and move it to a new column? Otherwise, I was going to write the script similar to below:
dt<<NEW column=""></NEW>
Re: For Loop for Moving Data to New ColumnsGlad you got a solution that works!
Re: For Loop for Moving Data to New ColumnsThanks for replying to my question. Originally "Column 2" wasn't the second column... and "Column 40" wasn't the 40th but I rearranged my srcpit so that it is. I couldn't get your script to work but I did decide to use transpose. The following works as I intended. Thanks for the idea!
dt = Current Data Table();
collist = dt << get column names;
dt << Select Rows( {7,8} );
dt<columns( eval(collist) ),
Source Label Column( "Label" ),
Transpose selected rows only( 1 ),
Output Table( "Transpose Demands" ));
dt2 = Data Table("Transpose Demands");
dt2 << Add Rows(7,0);
dt << Update( With( dt2 ));
Close(Data Table( "Transpose Demands" ), No Save);
dt << Delete Columns( "Label" );
Re: For Loop for Moving Data to New ColumnsApproximately this:
dt[ 9::47, { "Demand Parameter", "Demand Parameter Value" } ] = dt[ 7::8, 2::40 ] ` ;
if "Column 2" is the second column... and "Column 40" is the 40th. Note the final, tiny, ` at the end that means Transpose. You could also list all the column names instead of 2::40. The transpose is needed to make the Left Hand Side and the Right Hand Side be the same shape, 39 rows and 2 columns.
See Data Table Subscripting blog post.