2
$\begingroup$

I want to update the value of opening stock and closing stock by adding 20 when dcsDep2 < 3.028512. here is the snapshot of dataset:enter image description here

I tried with this code:

for(index_label,row_series) in dep1.iterrows():
    while row_series["Closing Stock"]<3.028512:
            dep1.at[index_label,"Closing Stock"]=row_series["Closing Stock"]+22

but no output is shown.

$\endgroup$

1 Answer 1

3
$\begingroup$

You can use df.loc to make the selection and then set the values. Take a look at this example and modify according to your dataset.

In [1]: import pandas as pd

In [2]: df = pd.DataFrame({'a':[1,2,3], 'b':[0.1,0.3,0.9], 'c':[4,5,6]})

In [3]: df
Out[3]: 
   a    b  c
0  1  0.1  4
1  2  0.3  5
2  3  0.9  6

In [4]: df.loc[df['b'] < 0.5, ['a', 'c']] += 20

In [5]: df
Out[5]: 
    a    b   c
0  21  0.1  24
1  22  0.3  25
2   3  0.9   6

Also, in future try to provide a sample from your dataset as a table of values and not an image so that it becomes easier to reproduce an example.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.