Something like this could work, if I'm understanding correctly. You'd need to change the list on line 3 to be the right list each time, and the Try section is there because the loop currently doesn't know what to do about the last grouping. If this is the right approach, you could remove the need for the Try section with some better conditionals. Script below to work with your sample data table:
dt = Data Table( "Sample_Data" );
lstStates = {"Initialization", "Ramp", "Heat", "Other"};
lstLocs = dt << Get Rows Where( Contains( :Current_State_Code, "amp" ) );
Try(
For Each( {i, j}, lstLocs,
For Each Row(
dt,
If( (Row() > lstLocs[j] & Row() < lstLocs[j + 1]),
:Current_State_Code = lstStates[j];
)
)
)
);