方法1:df.loc[conditions]=row.values,逐行地进行整行替换
for row in df.iterrows(): row['given_amount']=row['amount']; row['given_percent']=1 row['remain_amount']=0 row['remain_percent']=0 total_amount=total_amount-row['amount'] #df_debts.iloc[index]=row #此法不可行,会导致重新迭代。 df.loc[df['sno']==row['sno']]=row.values
方法2:用loc,批量赋值替换
indexer=df.loc[condition] df.loc[indexer,'col_1']=new_value df.loc[indexer,'col_2']=df.loc[indexer,'col_3']*10