I am creating a new column in an existing df with the values of the previous column in the i+1 position. This means the last value of the new column will remain empty.
The code is working in the sense the new df is correctly created but it is giving Key Error. I udnerstand the loop is not detecting how to stop. Seems to have a pretty simple solution but I have not been able to fix it so far. This is the code.
data = [['scn1', 100, ''], ['scn1', 150, ''], ['scn1', 300, '']]
OCS = pd.DataFrame(data, columns = ['scn', 'FROM', 'TO'])
for i in OCS.index:
a = i
i = i+1
lastvld = OCS.loc[i].FROM
maxloop = len(OCS)
if a <= maxloop:
OCS.loc[a, 'TO'] = lastvld
Any help will be very appretiated.