Why can't I use an object outside of the cell where it's defined?

In cell 1 I create a Pandas dataframe with:

df = pd.read_csv(...)

In the next cell (cell 2) I perform some operations on that dataframe. However, if there’s an error in that second cell, or I leave too much time between executing cells 1 and 2 I get the following error:

RuntimeError: Can't use object "df" outside of the cell where it's defined

I have to re-run cell 1 before I can execute cell 2. This is really frustrating, as creating this dataframe takes a non-negligible amount of time.

Is there any way to avoid this happening?

Hi @Alan_Buckeridge,

This error means that the Datalore kernel couldn’t persist the state for some reason. More info can be found here. In general, most of the operations on the dataframes shouldn’t lead to this error.

The easiest way to get rid of this problem is to switch to IPython kernel (Menu: Kernel → IPython kernel).