Reputation: 40818
Someone share a Jupyter notebook via Google Drive. https://drive.google.com/file/d/0B88HiG_KpEbQcVhNa1NpZzVrT3c/view?usp=sharing
I want to make the link a runnable version on Google Colab instead. How do I do that?
Upvotes: 5
Views: 9860
Reputation: 40818
First take the ID part from the Drive URL. Here the ID is 0B88HiG_KpEbQcVhNa1NpZzVrT3c
Then put it in the fileId parameter in Colab URL, like this. https://colab.research.google.com/notebook#fileId=0B88HiG_KpEbQcVhNa1NpZzVrT3c&offline=true&sandboxMode=true
Notice the offline and sandboxMode parameters. Without them, the notebook will be read-only. In that case, you need to either duplicate it or change to playground mode to make it runnable
Newer URL is in this format instead:
https://colab.research.google.com/drive/0B88HiG_KpEbQcVhNa1NpZzVrT3c#offline=true&sandboxMode=true
Upvotes: 10
Reputation: 11
from google.colab import auth
from googleapiclient.discovery import build
import io
from googleapiclient.http import MediaIoBaseDownload
import pandas as pd
auth.authenticate_user()
drive_service = build('drive', 'v3')
file_id = '1h1z-vGcNk1pt2U9Q8g9NR_L14txKLEos'
request = drive_service.files().get_media(fileId=file_id)
downloaded = io.BytesIO()
downloader = MediaIoBaseDownload(downloaded, request)
done = False
while done is False:
status, done = downloader.next_chunk()
df = pd.read_csv(StringIO(downloaded.getvalue()))
Upvotes: 1
Reputation: 1526
Easiest method- when the notebook is open in Colab:
Upvotes: 3