01 logo

Easy Downloading Kaggle Data To Google Drive!!

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

By Priyanka DandalePublished 3 years ago 3 min read
Like

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

Google Colaboratory is a free platform (environment might be a better word though!) for programmers to do coding! Beyond that, it is in essence developed to facilitate Machine Learning and Deep Learning research by providing free GPU and TPU resources!

In Google Colab:

  • You have access to a free GPU with limited runtime!
  • You write your code in a nice ready-to-use notebook.
  • Installing new packages is very easy!

Google Colab basically provide descent computation resources for whoever around the world that

  • desire to do Machine Learning and
  • have a Gmail account!

Taking about Machine learning, Deep Learning, or NLP 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 download and upload are consuming time.

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 the 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 ❤

If you liked the article, please share it, so that others can read it!

Happy Learning! 😊

how to
Like

About the Creator

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2024 Creatd, Inc. All Rights Reserved.