![](/img/trans.png)
[英]What is the best way to copy a pandas dataframe from one jupyter notebook to another
[英]In Jupyter Notebook, what is the best way to execute a function from another notebook?
我是 Jupyter Notebooks 的新手,並且使用 Python 3.7 的 Anaconda 安裝。 從另一個筆記本執行功能的最佳方法是什么? 我在這里找到了這個 2 歲的答案,但我不知道是否有新的/更好的方法來安裝 Anaconda(nbimporter 必須單獨安裝,它不在 Anaconda 中)。
這是筆記本中的代碼/信息:
嘗試 #1(失敗)
# working directory files:
# mytest.ipynb # this contains the function I am trying to call
# Untitled.ipynb # this is the Notebook I am working in
# mytest.ipynb contents:
def testfcn(x):
return print("input is", str(x))
# Untitled.ipynb contents:
from mytest import testfcn
testfcn(4)
ModuleNotFoundError: No module named 'mytest'
嘗試#2(好吧,不理想)
# Untitled.ipynb contents:
%run mytest.ipynb
testfcn(4)
# returns this, extra stuff:
0.019999999999999997
<class 'float'>
input is 4
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.