Want to access Kaggle datasets to Google Colab directly?

Krati Agarwal
Analytics Vidhya
Published in
2 min readMay 16, 2020

Most beginners in data science start their journeys by using Kaggle data sets and Google Colab. However, when it comes to accessing Kaggle data directly from Google Colab, many people are still unaware of it. This article will help you to access Kaggle data directly in Google Colab without downloading it externally.

To access Kaggle data in Google Colab notebook, follow the five easy steps.

Step 1

Firstly, we need to run the below command in the Google Colab shell.

! pip install -q kaggle

This will install Kaggle chi, a tool that will help us to download the data set directly from the command line.

Step 2

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

Step 3

Now go back to your Colab notebook and write the below-given command in a new shell and run the shell, this will generate to choose file option, upload the “kaggle.json” here.

from google.colab import files
files.upload()

Step 4

Now add another shell and add the below code to it and run the shell; a zip file will get downloaded in the current Google Colab data directory.

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

Step 5

To unzip the zipped file, we need to write the below command in the new shell and run it.

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

Hurray!, we are ready to use the Kaggle data sets in the Google Colab notebook.

--

--

Krati Agarwal
Analytics Vidhya

Data Science and Machine Learning enthusiastic. I believe in working on data to make data work for us.