Skip to content

Instantly share code, notes, and snippets.

@Vaidic
Last active February 17, 2021 17:51
Show Gist options
  • Save Vaidic/5aafd90b9fc2acfa42a20deee636a2c8 to your computer and use it in GitHub Desktop.
Save Vaidic/5aafd90b9fc2acfa42a20deee636a2c8 to your computer and use it in GitHub Desktop.

Revisions

  1. Vaidic revised this gist Feb 17, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Import Kaggle Dataset into Colab
    Original file line number Diff line number Diff line change
    @@ -22,4 +22,6 @@ os.chdir('/content/competitions/'+dataset)
    for file in os.listdir():
    zip_ref = zipfile.ZipFile(file, 'r')
    zip_ref.extractall()
    zip_ref.close()
    zip_ref.close()

    os.listdir()
  2. Vaidic revised this gist Feb 17, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Import Kaggle Dataset into Colab
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@ import zipfile
    import os

    api_token = {"username":"USERNAME","key":"KEY"}
    !mkdir /root/.kaggle
    with open('/root/.kaggle/kaggle.json', 'w') as file:
    json.dump(api_token, file)
    !chmod 600 /root/.kaggle/kaggle.json
  3. Vaidic created this gist Feb 17, 2021.
    24 changes: 24 additions & 0 deletions Import Kaggle Dataset into Colab
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    !pip uninstall kaggle -y && pip install kaggle
    import json
    import zipfile
    import os

    api_token = {"username":"USERNAME","key":"KEY"}
    with open('/root/.kaggle/kaggle.json', 'w') as file:
    json.dump(api_token, file)
    !chmod 600 /root/.kaggle/kaggle.json
    !kaggle config set -n path -v/content
    !kaggle config view

    dataset = 'titanic' # change this to the dataset to download
    os.environ['dataset']=dataset
    !echo $dataset

    !kaggle competitions download -c $dataset
    !ls /content/competitions/$dataset

    os.chdir('/content/competitions/'+dataset)
    for file in os.listdir():
    zip_ref = zipfile.ZipFile(file, 'r')
    zip_ref.extractall()
    zip_ref.close()