Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
715 views
in Technique[技术] by (71.8m points)

python - How to connect to an existing Jupyter Notebook kernel and inspect variables using the Variable explorer?

If I've got a kernel running through a Jupyter Notebook, I can easily connect to it from Spyder using Options > Connect to an exisisting kernel > Browse. Now I can get access to the Jupyter kernel and view the dataframe or any other variable by just running df:

Jupyter snippet:

#imports
import numpy as np
import pandas as pd

# Some sample data
np.random.seed(1234)
df = pd.DataFrame({'A1':np.random.normal(10, 1, 8),
                   'B1':np.random.normal(20, 2, 8)})

Spyder snippet:

df

# output:
          A1         B1
0  10.471435  20.031393
1   8.809024  15.514630
2  11.432707  22.300071
3   9.687348  21.983892
4   9.279411  21.906648
5  10.887163  15.957490
6  10.859588  19.331845
7   9.363476  20.004237

But why is the dataframe not available in the Variable Explorer in Spyder?

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

(Spyder maintainer here) This happens because the kernels that are created by the notebook doesn't have the functionality necessary to display its namespace in our Variable Explorer.

And there's no easy workaround for that at the moment, sorry.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...