Easy Downloading Kaggle Data To Google Drive!!

Priyanka Dandale
Nerd For Tech
Published in
4 min readMay 13, 2021

Downloading Kaggle data to Google drive and readily using it in Google Colab!

Kaggle is the world’s largest data science community with powerful tools and resources to help you achieve your data science goals.

Taking about Machine learning, Deep Learning, NLP, or AI, these require quite serious processing. Many people tend to use Google Colab for model training since the GPUs and TPUs available for free. One drawback of Colab is that the model no longer remains when quitting the notebook (unless you are the pro user). The solution is to move the workspace to Google Drive because it can be saved all information after leaving the notebook. The downloads and uploads are time-consuming.

How to directly download the Kaggle dataset to Google Drive? — — Everything will be on the cloud for sure!

Follow the below 6 easy steps:

  1. Create New API Token from Kaggle Account
  2. Mount your Google drive to Google Colab
  3. Configure environment on Google Colab
  4. Get the Kaggle API
  5. Use the Copied API command in Colab
  6. Unzip the file to use it!

1. Create New API Token from Kaggle Account

Go to your Kaggle website. If you do not have a Kaggle account then first you need to create it. Once done open your account details, scroll down to the API section click on “Create New API Token”.

Your web browser will ask you to download JSON file, named kaggle.json. The file contains the Username and the Key that will be used for config the Google Colab environment. After downloading it successfully, you will get the below message.

2. Mount your Google Drive to Google Colab

Use the below code to mount the Google drive. You may change the directory to some folder in your drive but remember dataset will be downloaded to that directory.

from google.colab import drive

drive.mount(“/content/drive”)

After executing the above two lines of code, it will ask you to go to a URL, click on it and sign in to your Google Drive account and copy the code.

Paste the copied code under ‘Enter your authorization code’.

After clicking enter, in some time you will get following message:

Don’t forget to mount the Google Drive. Otherwise, your data will be lost anyway!

3. Configure environment on Google Colab

Now create the new notebook for the coding config environment. Insert a new cell and type the below code for configuring the environment.

Please note that the Username and the Key which you will get from kaggle.json are case-sensitive. You have to type exactly the same Username and the Key, otherwise, it will throw an error.

#Configuration environment

import os

os.environ[‘KAGGLE_USERNAME’] = “priyankadandale”

# username from the json file

os.environ[‘KAGGLE_KEY’] = “9f9d3c58210dda1dc770b62db060e304”

# key from the json file

4. Get the Kaggle API

We are now ready to use Kaggle API. To use it, go to the link we needed and find “three dots” somewhere on the right side of the page. Then, select Copy API command.

5. Use the Copied API command in Colab

Come back to Google Colab notebook. Insert the new cell and type ‘!’ at the beginning followed by the API command.

#Download hr-analytics-job-change-of-data-scientists data from Kaggle API

!kaggle datasets download -d arashnic/hr-analytics-job-change-of-data-scientists

See the below image, you will get the message after successfully downloading the data files. You will get the size of the downloaded files also.

6. Unzip the file to use it!

Use the below code on the next cell.

!unzip -q “/content/hr-analytics-job-change-of-data-scientists.zip”

Copy the path of the file to want to read or perform any other operation.

Done! 😊

Thanks for Reading!!

For any suggestions or queries, leave your comments below and follow for updates.

If you liked the article, please hit the 👏 icon to support it. This will help other Medium users find it. Share it, so that others can read it!

Happy Learning! 😊

--

--

Priyanka Dandale
Nerd For Tech

Senior Unit Manager — BFL, Ex-Accenture, Ex-Infosys, Data Scientist, AI Engineer, MSc. Statistics SPPU.