I have a dataframe that looks like this (with more rows):
Buy Sell acct_stock usd_account
0 True False
1 False True
I assigned two numerical values to two variables like so:
account = 1000
stock_amount = 0
For each row in the df that has the combination of True AND False
, I want to update columns acct_stock
and usd_account
by using the numerical variables to do calculations:
I have come up with the following FOR
loop:
for index,row in df.iterrows():
if (row['Buy'] == True & row['Sell'] == False):
row['acct_stock'] = (account * 0.02)/row[4]
row['usd_account'] = account - (stock_amount * 0.02)
When I run this the columns acct_stock and usd_account
do not get updated at all, even for rows where the conditions are met.
What am I doing wrong that the calculations are not being assigned by index to the columns/rows in question and the variables 'account'
and 'stock_amount
' are also being updated continously?