简体   繁体   中英

Why does Python error code 'name is not defined' appear after you left the jupyter notebook and came back the next day and how to fix it?

Name is not defined I was working on Jupyter Notebook and ended up saving the notebook after working for hours, now when I want to return back the notebook is giving me errors. I thought by saving it and coming back the next day I will find it where I previously left it and would continue from there but as I continue it gives me the error code name is not defined

I tried import pandas and numpy and was expecting the error code to stop

When you save a notebook it only saves the python code in the cells and their respective outputs if there are any.

Saving a notebook does not mean that you can just start it from where you left it, meaning that the variables which you initialised are lost once you turn off the jupyter notebook kernel. All you need to do is re-run each cell in your notebook and all the variables will load since they have to be in the notebook. Hope this helps!

Re-run all the cells from the top down.

In one of the previous cells you defined / imported normal_rets . But until you run that specific cell again, the notebook doesn't know what normal_rets is.

When you save the notebook, you effectively save the code / instructions. But you need to re-run the code cells when you come back to the notebook so that all of the functions / modules / variables and their contents are re-loaded into memory so you can use them again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM