Moving data from Kaggle to Colab and back

Kaggle to Colab

To move data from Kaggle to Google Colab, start a new notebook, add the competition dataset / public dataset (not implemented for notebook output files) and run

from kaggle_datasets import KaggleDatasets
print(KaggleDatasets().get_gcs_path("nbme-score-clinical-patient-notes"))
      

This returns something like

gs://kds-699190c77548f6bf51c09422041915db0d8c60ef7e3b1cab985b9271
      

In Google Colab it is then possible to load this dataset through

!gsutil -m cp -r gs://kds-699190c77548f6bf51c09422041915db0d8c60ef7e3b1cab985b9271 .
!mv kd* nbme-score-clinical-patient-notes
      

Colab to Google Drive

To save results of Colab run to Google Drive, do

from google.colab import drive
drive.mount('/content/drive')
!cp file.txt /content/drive/MyDrive/
      

Google Drive to Kaggle

To move data from Google Drive to Kaggle, one needs to allow sharing for everyone with the link and obtain the links. They look as follows:

https://drive.google.com/file/d/FILEID/view?usp=sharing
      

and the important part is the FILEID. To be able to transfer to Kaggle, we need to obtain a Google Drive API key first. With it, we can start a new dataset on Kaggle and use the link

https://www.googleapis.com/drive/v3/files/FILEID/?key=APIKEY&alt=media
      

to upload the file.

11 Apr 2022