import pandas as pd // imports pandas package to create datsfranme
from IPython.display import display // import display to display your dataframe
import numpy as np
create your dataframe with 5 columns and 5 columns
A = pd.DataFrame({"index":[1,2,3,4,5], "date
from":["1/2/2017","2/2/2017","3/2/2017","4/2/2017","5/2/2017"],
"date until":
["1/3/2017","2/3/2017","3/3/2017","4/3/2017","5/3/2017"],
"product":["a","b","c","d","e"] ,
"wap":[100,200,300,400,500] })
create the new column you need
A["wap_update"]=np.nan
display your dataframe
display(A.head())
for i in range(len(A)):
if (i<len(A)-1):
A.at[i,"wap_update"] = (A.iloc[i]['wap'] )+ (A.iloc[i+1]['wap'])
else :
A.at[i,"wap_update"]=A.iloc[i]['wap']
display(A)
A.iloc[i]['wap'] will get values at i row and "wap" column
A.at[i,"wap_update"] will set the value at at i row and "wap" column
range(len(A)-1)A1. This doesn't have any effect.