如何快速远程加载kaggle数据集
Published on Aug. 22, 2023, 12:10 p.m.
在colab平台上使用kaggle家数据集资源
!pip install kaggle
-*- coding: utf-8 -*-
=====================
"""kaggle数据集加载.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/gist/napoler/cc05bf83dc19e26ea8b828c983d8cfdb/kaggle.ipynb
"""
api\_key = "" #@param {type:"string"}
=====================================
api\_token = {"username":"USERNAME","key":api\_key}
===================================================
api\_token = {"username":"terorg","key":"5c8d80bf3084dc6ee"} #@param {type:"raw"}
Info on how to get your api key (kaggle.json) here: https://github.com/Kaggle/kaggle-api#api-credentials
========================================================================================================
import json
import zipfile
import os
!mkdir /content/.kaggle/
========================
with open('/root/.kaggle/kaggle.json', 'w') as file:
json.dump(api\_token, file)
!chmod 600 /content/.kaggle/kaggle.json
=======================================
!kaggle config path -p /content
===============================
!kaggle competitions download -c jigsaw-toxic-comment-classification-challenge
==============================================================================
os.chdir('/content/competitions/jigsaw-toxic-comment-classification-challenge')
===============================================================================
for file in os.listdir():
=========================
zip\_ref = zipfile.ZipFile(file, 'r')
=====================================
zip\_ref.extractall()
=====================
zip\_ref.close()
================