IIUC: You can try using .groupby item number followed by .shift in dataframe as following.
Suppose the original dataframe is as below:
DIV_NBR itm_nbr WEEK_NO DISTINCT_ITM_CNT INVENTORY_IN_HAND
0 18 65874 201511 5.0 2925.0
1 18 65874 201512 5.0 2910.0
2 18 65874 201513 5.0 2961.0
3 19 65875 201511 5.0 2965.0
4 19 65875 201512 5.0 2971.0
Then:
# keep record of last week by grouping by item number and then using shift
df['LAST_WEEK'] = df.groupby('itm_nbr')['INVENTORY_IN_HAND'].shift()
# check if current inventory is greater than last week
df['Flag'] = (df['INVENTORY_IN_HAND'] - df['LAST_WEEK'])>0
# delete additional column
del df['LAST_WEEK']
# change flag int
df['Flag'] = df['Flag'].astype(int)
print(df)
Result:
DIV_NBR itm_nbr WEEK_NO DISTINCT_ITM_CNT INVENTORY_IN_HAND Flag
0 18 65874 201511 5.0 2925.0 0
1 18 65874 201512 5.0 2910.0 0
2 18 65874 201513 5.0 2961.0 1
3 19 65875 201511 5.0 2965.0 0
4 19 65875 201512 5.0 2971.0 1
forloop inside aforloop?