My small script on value alteration in columns of a data not working
FYI, I did not go through your code as it is fairly straight forward assuming I had understood it right.

&gt;&gt; import pandas as pd
&gt;&gt; import random
&gt;&gt; df = pd.DataFrame({'a': np.random.rand(10), b: np.random.rand(10)})
&gt;&gt; print(df)
          a         b
0  0.127409  0.508811
1  0.345239  0.674797
2  0.824521  0.381567
3  0.893538  0.062142
4  0.307070  0.769546
5  0.872883  0.175192
6  0.046671  0.592971
7  0.799977  0.632761
8  0.932829  0.456906
9  0.188867  0.470296
&gt;&gt; idx = random.sample(df.index, int(len(df)*0.2)) # random indices from dataframe selection, 20% of them are selected based on 0.2
&gt;&gt; print(idx)
[6, 0]
&gt;&gt; df[df.index.isin(idx)] = [0, 0]
&gt;&gt; df
          a         b
0  0.000000  0.000000
1  0.345239  0.674797
2  0.824521  0.381567
3  0.893538  0.062142
4  0.307070  0.769546
5  0.872883  0.175192
6  0.000000  0.000000
7  0.799977  0.632761
8  0.932829  0.456906
9  0.188867  0.470296


Hope it helps.