xxxxxxxxxx
from google.colab import files
import os
#if you've already uploaded kaggle.json before, don't do it again
if not(os.path.exists("kaggle.json")):
files.upload() #upload kaggle.json
!pip install --upgrade --force-reinstall --no-deps kaggle
!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/
!ls ~/.kaggle
!chmod 600 /root/.kaggle/kaggle.json
#COMPETITION DATASET
dataset_name="name of competition" #you can find this on the competition data page
!kaggle competitions download -c {dataset_name}
!mkdir {dataset_name}
!unzip -q {dataset_name}.zip -d {dataset_name}
!rm -f {dataset_name}.zip
#Public Dataset
dataset_url="NAME OF DATASET"
dataset_name=dataset_url.split("/")[1]
!kaggle datasets download -d {dataset_url}
!mkdir {dataset_name}
!unzip -q {dataset_name}.zip -d {dataset_name}
!rm -f {dataset_name}.zip
xxxxxxxxxx
"""
You need an API token. This token can be easily generated from the profile
section of your Kaggle account. Simply, navigate to your Kaggle profile and
then Click the Account tab and then scroll down to the API section
A file named “kaggle.json” will be download which contains the username and
the API key.
>>>upload the “kaggle.json” file that you just downloaded from Kaggle to colab<<<
"""
"this worked for me"
# NOW run below code
! pip install -q kaggle
!rm -r ~/.kaggle
!mkdir ~/.kaggle
!mv ./kaggle.json ~/.kaggle/
!chmod 600 ~/.kaggle/kaggle.json
# For Competition Dataset
! kaggle competitions download <name-of-competition>
# For "just" Dataset
! kaggle datasets download <name-of-dataset>
xxxxxxxxxx
Create api key
and yout colab:
from google.colab import files
files.upload() #upload kaggle.json
!pip install --upgrade --force-reinstall --no-deps kaggle
!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/
!ls ~/.kaggle
!chmod 600 /root/.kaggle/kaggle.json
!kaggle competitions -h
!kaggle competitions download -c DATASET
download kaggle dataset in colab
xxxxxxxxxx
import os
# You can use my dummy account =)
os.environ['KAGGLE_USERNAME'] = "whydoihavetodothiseh"
os.environ['KAGGLE_KEY'] = "1c0534cf33c5d00bb380dc4aebadd907"
# Dataset link from "Copy API command" button at kaggle
!kaggle datasets download -d mathchi/churn-for-bank-customers
# unzip last downloaded zip
!unzip -o $(ls -hat | grep -m 1 ".zip")
# equivalent to
# !unzip -o churn-for-bank-customers.zip
import pandas as pd
churn = pd.read_csv("churn.csv")
churn.head()
xxxxxxxxxx
def pull_kaggle_data(username,key):
import json
! mkdir .kaggle
token = {"username":username,"key":username}
with open(".kaggle/kaggle.json", "w") as file:
json.dump(token, file)
! cp .kaggle/kaggle.json ~/.kaggle/kaggle.json
================================================================================
pull_kaggle_data(username,key)
! kaggle competitions download -c malware-classification