Dataframe in Sheet1 not available in Sheet2

I am using Anaconda Code in Excel and I have the following code in Sheet1 of the Workbook
REF(“A42:E57”)
df2 = to_df(REF(“A42:E57”))
In Sheet2 I have the following formula referencing the df2 dataframe
find_value = df2.loc[df2[‘Renglon1’] == xl(“P21”), ‘Renglon3’].values[0]
I get the error message “name df2 is not defined”.
Could someone help me?

Anaconda Code cells can run in 2 different modes: Linked and Isolated.

Linked mode is how Python in Excel works where cells run in row-major order and subsequent cells have access to local variables defined in previous cells (like how a Jupyter notebook works).

In Isolated mode, each cell is fully isolated and only has access to the variables it defines. Isolated cells can only access other variables using REF. This is the default mode for Anaconda Code.

So you can fix your issue in one of two ways:

  1. Toggle both cells to Run Linked.
    Screenshot 2024-09-12 at 9.33.04 AM

  2. In the cell on Sheet2, declare variable df2 = to_df(REF("Sheet1!J12")) (I’m assuming the code in Sheet1 is in cell J12; change it to whatever the actual cell on Sheet1 is).

1 Like