loop through a dataframe column and modify each value 1

loop through a dataframe column and modify each value

for idx, row in df.iterrows():
    if  df.loc[idx,'Qty'] == 1 and df.loc[idx,'Price'] == 10:
        df.loc[idx,'Buy'] = 1

Here is what the above code is Doing:
1. Iterating through each row in the dataframe
2. Checking if the Qty is 1 and Price is 10
3. If the above condition is true, then we are setting the value of Buy column to 1

Similar Posts