I'm reading temperature data from a sensor that is cycling on and off in a dataframe df. Each time the sensor turns on, it takes roughly 5 rows of data to thermally equilibrate. I want to ignore the decreased temp values from the warm up time of the sensor in any statistics that would be run on the temperature column, and also ignore them when plotting. The three columns in the data frame are 'Seconds', 'Sensor_State', and 'Temperature'. I have created a fourth column called 'Sensor_Warmup_State' that is created with a loop, and turns all values to 0 after a 0 is detected in the 'Sensor_State' column in the next 5 cells. Then I multiply 'Temperature' by 'Sensor_Warmup_State' to get 'Processed_Temp'. This works, but I know there should be a more pythonic, faster way to do this, I just don't have the expertise yet.
Here's what I have. To create the dataframe:
import numpy as np
a=np.arange(1,21).tolist()
b = (np.zeros((2), dtype=int)).tolist()
c = (np.ones((18), dtype = int)).tolist()
d = b + c
e = [0,0,1,2,4,8,9,10,10,10,10,10,10,10,10,10,10,10,10,10]
data = {'Seconds': a, 'Sensor_State': d, 'Temperature': e}
df = pd.DataFrame.from_dict(data)
df['Sensor_Warmup_State'] = 0
df

To create the final two columns:
NumOfRows = df['Sensor_State'].size
x=0
for index, value in df['Sensor_State'].iteritems():
if (value == 0) & (index < NumOfRows-5):
df['Sensor_Warmup_State'].iloc[index] = 0
elif (value == 1) & (index < NumOfRows-5):
df.loc[(index + 5), 'Sensor_Warmup_State'] = 1
df['Processed_Temp'] = df['Sensor_Warmup_State'] * df['Temperature']
df

OP here, I figured out a better way by using .shift(), this is much simpler and 30% faster than looping through as initially outlined. I edited the starting dataframe to account for when the Sensor_State goes from 0 to 1, back to 0 and to 1 to account for these circumstances. Hope this helps someone:
The new code: