我有一个数据帧,看起来像这样(有更多的行):
Buy Sell acct_stock usd_account
0 True False
1 False True我将两个数值赋给两个变量,如下所示:
account = 1000
stock_amount = 0对于df中具有True AND False组合的每一行,我希望通过使用数值变量进行计算来更新列acct_stock和usd_account:
我想出了以下FOR循环:
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)当我运行此命令时,列acct_stock and usd_account根本不会更新,即使是满足条件的行也不会更新。
我做错了什么,没有通过索引将计算分配给相关的列/行,并且变量'account'和'stock_amount‘也在不断更新?
https://stackoverflow.com/questions/61151545
复制相似问题