You’d have to provide examples and details for anyone here to be able to offer clues. Plus, you should compare to Python outside of Jupyter, or is that what you mean by ‘in VSCode’? I’m assuming Python since you say you have very similar code; however, specifying is important as Jupyter can run code from a lot a lot languages.
Ideally your example would be be a minimal reproducible example. Likely looking into making that or sorting out which versions of Python are being used where, you’ll find the issue. Importantly, this is likely not a Jupyter issue and not pertinent to this site.
Please read Getting good answers to your questions and let that guide inform you how to better improve your posts.