I have a table like below:
I want to create another column(Check2) with below logic:
Expected Output should be like below -
I have written below code but its taking very long time(in hours) for 50000 records, please help
for i in range(len(df)):
if df.loc[i,'Check1'] == 0:
df.loc[i,'Check2'] = df.loc[i,'Volume']
else:
df.loc[i,'Check2'] = df.loc[i-1,'Check2'] - df.loc[i-1,'B'] -df.loc[i-1,'C']
You are searching for: .shift() function. It does what you want
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.