Download Kaggle Dataset to Google Drive

At First, mount your drive to Colab Notebook.
from google.colab import drive
drive.mount(‘/content/drive’)
- Go to path where you want to download the dataset in your drive. Mine was:
%cd /content/drive/My Drive/Colab_Notebooks/dataset1
2. Take your Token from Kaggle. For this:
- Go to My Account (Not My Profile).
- Go to API Section and click on Create New API Token.
- Download the token, which will be saved as a .json file (e.g. kaggle.json).
3. Use this code to upload API Token from Kaggle:
from google.colab import files
files.upload()
4. Run this 4 lines of code:
!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/
!chmod 600 ~/.kaggle/kaggle.json
!rm kaggle.json
5. Go to your desired Dataset page. Agree with the terms and then copy the API Command. (Note: Give “!” before kaggle). e.g.:
!kaggle datasets download -d biaiscience/dogs-vs-cats
6. (optional) To unzip files:
from zipfile import ZipFile
file_name=”/content/drive/My Drive/Colab_Notebooks/dataset1/dogs-vs-cats.zip”
with ZipFile(file_name,’r’) as zip:
zip.extractall()
print(‘Done’)
Image taken from:
https://vocal.media/01/easy-downloading-kaggle-data-to-google-drive