I am trying to have a code that does the following:
#create a new column in a dataframe
df['new_column'] = 0
and for every row in this dataframe, it looks at whether column B's value is 1. If it is, it populates the new column with a 1, it then jumps 126 rows forward, and populates that row of the new column with a -1; otherwise, it populates the row of the new column with a 0. Once done that, the formula should continue from a row that would depend on the value encountered in the column B (i.e., if in the first iteration, column B's value=1, the row from which the loop restarts will be 127, alternatively it would be row 2)
for row in df.iterrows():
for item in df['new_column']:
if df.B[df.new_column[df.new_column.index[item]]] == 1:
item = 1
row += 126
item = -1
else:
item = 0
Problem is that I get: "TypeError: can only concatenate tuple (not "int") to tuple". Could you please help me?