我正在使用google colab处理jupyter笔记本电脑(所有文件都在驱动器中)。我有两个文件: Exploratory_Data_Analysis.ipynb et PCA.ipynb。我想导入以使用第二个中第一个开始的数据。只在本地使用jupyter笔记本电脑(不使用google colaboratory),导入工作很简单,只需这样做:
!pip install import-ipynb
import import_ipynb
import Exploratory_Data_Analysis as eda但在google colab上,我尝试了以下几种方法:
!pip install import-ipynb
import import_ipynb
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
import os
import pandas as pd
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
listed = drive.ListFile({'q': "'1CXqv7-PZmYrWes4MOk' in
parents and trashed=false"}).GetList()
for file in listed:
print('title {}, id {}'.format(file['title'], file['id']))
eda = os.path.join(download_path, 'Exploratory_Data_Analysis.ipynb')
temp_eda = drive.CreateFile({'id': '1YpDhXGeJVtzuxUJS5gKsUbm'})
temp_eda.GetContentFile(eda)
import Exploratory_Data_Analysis并得到以下结论:
importing Jupyter notebook from Exploratory_Data_Analysis.ipynb
NotJSONError: Notebook does not appear to be JSON: ''...有没有其他方法可以在google colab上导入自己的ipynb文件?
发布于 2019-01-04 22:33:01
您是否成功地将您的笔记本/ipynb文件导入到Google Colab项目中?我将本地jupyter-notebook中正在进行的工作迁移到Google Colab的方法是使用Github和Clouderizer。这种方法还允许我在jupyter笔记本电脑环境中工作,就像我在本地做一样,但能够将我的工作即时同步到 Colab 。此外,此方法允许我将模块.ipynb/.py导入到我正在处理的笔记本中,只需执行类似import <my own python/ipynb module>的操作即可。我建议使用这种设置,而不是在Google Colab上使用hairy命令行。
以下是如何使用Clouderizer:Medium tutorial从github轻松设置您的笔记本到Google Colab的教程。
基本上,以下是使用Clouderizer设置ipynb笔记本和dataset文件夹所需的步骤:
用于Google Colab项目的Clouderizer
先决条件
安装Clouderizer项目
发布于 2019-04-08 03:25:50
下面的代码对我来说非常好用。1.将所有ipynb文件复制到colab 2中的一个文件夹中。共享colab中的ipynb文件,请参阅链接:https://www.pingshiuanchua.com/blog/post/importing-your-own-python-module-or-python-file-in-colaboratory 3。然后执行以下步骤:
!pip install import-ipynb
import import_ipynb
# Install the PyDrive wrapper & import libraries.
# This only needs to be done once per notebook.
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
# This only needs to be done once per notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# Copy the link and remove the front part of the link (i.e. https://drive.google.com/open?id=) to get the file ID.
your_module = drive.CreateFile({'id':'eyetgd1zyxwvutsrqponmlkjihgfedcba'})
your_module.GetContentFile('myfile.ipynb')
import myfilehttps://stackoverflow.com/questions/53254703
复制相似问题