Jupter notebook skips some iterations

The jupter notebook will skip some traversal sequences when executing loops, or sometimes skip the line print and execute the code that follows it, or occasionally print a space between two lines of print. However, these problems do not necessarily recur when the corresponding sequence of the error is re-executed。For example:
for sample_idx, sample in test_df[1536:1555].iterrows():
sequence, target = sample[“sequence”], sample[“target”]
print(f"idx: {sample_idx}, sequence: {sequence}“)
print(f"idx: {sample_idx}, target : {target}/{id2label[target]}”)
result = clf(sequence)
label = result[“label”]
response = result[“response”]
print(f"idx: {sample_idx}, label : {label}/{id2label[label] if label != -1 else ‘unknown’}")
The first two “print” were not revealed.The third print is shown dirictly.

And there also occur a Null String between the first two “print” sometimes.But when I re-run the faulty iteration, these problems don’t appear again, or in the same place

You’ve left out details of an important test:
Does this behavior happen when you run this code directly in Python or not?

If you run this in a Python script or in the Python console/interpreter directly and see the same behavior then Jupyter isn’t involved and this isn’t pertinent here.

What you’ve provided isn’t a minimal reproducible example that is self-contained. We cannot run that code and test if we see what you are reporting.
Additionally, it isn’t formatted so that we don’t need to edit it to run it. Please provide code here formatted as code blocks and not text, see here, with special attention to ‘Block code formatting’.

More on the reproducibility:
What is the source of the function being used next line? I assume it is some machine learning package but you don’t let us know. We’d need import statements.

A lot of what you describe seems to probably come from exhausting an iterator and not realizing that. But again, we cannot tell because we have only a glimpse of what is going on and not idea of the full picture…