Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading data from a shared google drive link in google colab

I want to download data from google drive link shared by someone using google colab. I am a new user of colab and I don't know how to do that. the links are

x_train: https://drive.google.com/open?id=1cUaIEd9-MLJHFGjLz5QziNvfBtYygplX

y_train: https://drive.google.com/open?id=1hv24Ufiio9rBeSqgnNoM3dr5sVGwOmBy

x_test: https://drive.google.com/open?id=1AH9lKHT5P2oQLz8SGMRPWs_M9wIM2ZRH

y_test: https://drive.google.com/open?id=1i4_azocSDuU3TcDf3OSHO1vF0D5-xMU6

Thanks in advance

like image 745
Fu678 Avatar asked Jul 06 '20 15:07

Fu678


People also ask

How do I transfer data from Google Drive to Google Colab?

You can use the upload option at the top of the Files explorer to upload any file(s) from your local machine to Google Colab. Step 2: Click the upload icon and select the file(s) you wish to upload from the “File Upload” dialog window.

How do I import data from link into Google Drive?

Drag files into Google Drive On your computer, go to drive.google.com. Open or create a folder. To upload files and folders, drag them into the Google Drive folder.

How to import data from Google Drive to Colab?

Executing the following two lines of code will import the data into Colab: import pandas as pd pd.read_csv('/content/gdrive/My Drive/sample data/sample.csv') Importing Data from Local System. Step1 Run the following two lines of code to import data from the local system. from google.colab import files uploaded = files.upload()

How to add Google Drive shortcut to Colab notebook?

Create a shortcut to this file in your Google Drive (right-click on file -> "Add shortcut to Disk") Mount your Google drive in Colab notebook (click buttons: "Files" -> "Mount Drive") Now you can access this file via your shortcut for !unzip/np.load/ ...

How to download data from Google Drive to a notebook?

Click on the arrow on the left and you will find the data structure. For your easy usage, just save the below code snippet and paste it into the Google Colab and you can mount your Google Drive to the notebook easily. In this section I will share with you my experience in downloading dataset from Kaggle and other competition.

How to download data from Google Drive to Kaggle?

Step 1 First, go to your Google Colab then type the below: If you are able to access Google Drive, your google drive files should be all under: In this section I will share with you my experience in downloading dataset from Kaggle and other competition. Visit www.kaggle.com ⇨ login ⇨ My Account ⇨ Create New API Token


1 Answers

You can use gdown if the file is shared publicly.

!gdown --id 1cUaIEd9-MLJHFGjLz5QziNvfBtYygplX

If it's shared to you only, you need to use pydrive

# Install the PyDrive wrapper & import libraries.
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.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

file_id = '1cUaIEd9-MLJHFGjLz5QziNvfBtYygplX'
downloaded = drive.CreateFile({'id':file_id})
downloaded.FetchMetadata(fetch_all=True)
downloaded.GetContentFile(downloaded.metadata['title'])

If they share a folder, it's too long so I made it short in my library.

!pip install kora
from kora import drive
drive.download_folder('1HvIeNhqtFVllXFWzH5NawDdnIfgGDwCK')
like image 60
korakot Avatar answered Oct 07 '22 16:10

korakot