Skip to content Skip to sidebar Skip to footer

Download Kaggle Dataset By Using Python

I have trying to download the kaggle dataset by using python. However i was facing issues by using the request method and the downloaded output .csv files is a corrupted html files

Solution 1:

Basically, if you want to use the Kaggle python API (the solution provided by @minh-triet is for the command line not for python) you have to do the following:

import kaggle

kaggle.api.authenticate()

kaggle.api.dataset_download_files('The_name_of_the_dataset', path='the_path_you_want_to_download_the_files_to', unzip=True)

I hope this helps.

Solution 2:

kaggle api key and usersame is available on kaggle profile page and dataset download link is available on dataset details page on kaggle

#Set the enviroment variables
import osos.environ['KAGGLE_USERNAME'] = "xxxx"os.environ['KAGGLE_KEY'] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
!kaggle competitions download -c dogs-vs-cats-redux-kernels-edition

Solution 3:

I would recommend checking out Kaggle API instead of using your own code. As per latest version, an example command to download dataset is kaggle datasets download -d zillow/zecon

Solution 4:

Full version of example Download_Kaggle_Dataset_To_Colab with explanation under Windows that start work for me

#Step1#Input:
from google.colab import files
files.upload()  #this will prompt you to upload the kaggle.json. Download from Kaggle>Kaggle API-file.json. Save to PC to PC folder and choose it here#Output Sample:#kaggle.json#kaggle.json(application/json) - 69 bytes, last modified: 29.06.2021 - 100% done#Saving kaggle.json to kaggle.json#{'kaggle.json': #b'{"username":"sergeysukhov7","key":"23d4d4abdf3bee8ba88e653cec******"}'}#Step2#Input:
!pip install -q kaggle
!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/
!ls ~/.kaggle
!chmod 600 /root/.kaggle/kaggle.json  # set permission#Output:#kaggle.json#Step3#Input:#Set the enviroment variables
import os
os.environ['KAGGLE_USERNAME'] = "sergeysukhov7"#manually input My_Kaggle User_Name 
os.environ['KAGGLE_KEY'] = "23d4d4abdf3bee8ba88e653cec5*****"#manually input My_Kaggle Key #Step4#!kaggle datasets download -d zillow/zecon #download dataset to default folder content/zecon.zip if I want #find kaggle dataset link (for example) https://www.kaggle.com/willkoehrsen/home-credit-default-risk-feature-tools and choose part_of_the_link - willkoehrsen/home-credit-default-risk-feature-tools#set link_from Kaggle willkoehrsen/home-credit-default-risk-feature-tools#set Colab folder download_to  /content/gdrive/My Drive/kaggle/credit/home-credit-default-risk-feature-tools.zip
!kaggle datasets download -d willkoehrsen/home-credit-default-risk-feature-tools -p /content/gdrive/My\ Drive/kaggle/credit 

#Output#Downloading home-credit-default-risk-feature-tools.zip to /content/gdrive/My Drive/kaggle/credit#100% 3.63G/3.63G [01:31<00:00, 27.6MB/s]#100% 3.63G/3.63G [01:31<00:00, 42.7MB/s]

Solution 5:

Before anything:

pip install kaggle

For the dataset:

import os
os.environ['KAGGLE_USERNAME'] = "uname"# username from the json file
os.environ['KAGGLE_KEY'] = "kaggle_key"# key from the json file
!kaggle datasets download -d zynicide/wine-reviews

For the competitions:

import os
os.environ['KAGGLE_USERNAME'] = "uname"# username from the json file
os.environ['KAGGLE_KEY'] = "kaggle_key"# key from the json file
!kaggle competitions download -c dogs-vs-cats-redux-kernels-edition

Some time ago I provided another similar answer.

Post a Comment for "Download Kaggle Dataset By Using Python"