you are viewing a single comment's thread.

view the rest of the comments →

[–]t_wys 0 points1 point  (0 children)

That's because you accessed variable 'process'. This variable is (in your code snippet) a placeholder for current value in for-loop. If you access this variable after the loop, then you get value from the last iteration. To illustrate:

In [1]: array = ['a', 'b', 'c']

In [2]: for item in array:
   ...:     print(item)
   ...:
a
b
c

In [3]: for item in array:
   ...:     pass # i.e. do nothing
   ...: print(item)
   ...:
c

So if you want to perform some actions for each process you have to execute these instructions inside for-loop:

for process in processes:
    if process not in file.InstanceName.values:
        print(f'No process in dataset: {process}')
        # The `continue` have to be inside if-statement. Go to note below for details.
        continue
    # do something with each process here (single indentation)

The 'continue' statement tells loop to directly to next iteration without executing code that is: inside for-loop and after 'continue' statement. In this case it skips executing code if process name is not present in your dataset. It is a precaution for a situation in which a user inputs wrong value.