Want to directly access Kaggle datasets to Google Colab?

Original article was published on Deep Learning on Medium

Want to directly access Kaggle datasets to Google Colab?

The easiest method to access your Kaggle datasets in Goggle Colab.

Most of the beginners in data science start their journey with the help of the Kaggle dataset and a Google Colab but when it comes to accessing Kaggle data directly from google Colab they are still unaware of it. So this article will help you in accessing the Kaggle data in Google Colab directly with downloading it externally.

In order to access Kaggle data in your google Colab notebook follow the five easy

steps and use any Kaggle dataset in your Goggle Colab notebook.

Step 1

Firstly we need to run the below command

! pip install -q kaggle

This installs kaggel cli a tool that will help us to download the dataset directly from the command line.

Step 2

Sign in in your Kaggle account and click on my account page and click on create a new API token option and this will automatically download a “kaggle.json” file.

Step 3

Now go back to your Colab notebook and write the below command in a new shell and run the shell and this will ask to choose the file option, now upload the “kaggle.json” you downloaded earlier.

from google.colab import files
files.upload()

Step 4

By running the below code, a zip will get downloaded in the current directory.

! mkdir ~/.kaggle
! cp kaggle.json ~/.kaggle/
! chmod 600 ~/.kaggle/kaggle.json
! kaggle datasets download -d dataset filename

Step 5

Now Unzipping Data in the database folder by using the below commands

import zipfile
local_zip = “dataset filename.zip”zip_ref = zipfile.ZipFile(local_zip, ‘r’)
zip_ref.extractall(‘./database’)
zip_ref.close()

Now you are ready to use your dataset directly from Kaggle in your Goggle Colab notebook.