Noob tip of the day. I love Colab. I use it for everything.

Up until now I’ve been keeping my data on Google Drive and loading it by mapping my drive at the top of the notebook, like this.

from google.colab import drive
drive.mount("/content/drive")
df = pd.read_csv("/content/drive/My Drive/Python/Data/Titanic/train.csv")

That’s ok except that every time you run the notebook you have to click a link the first time it does the drive.mount() and go get an auth token to paste back into the notebook cell. It also means nobody else can run this notebook as they’d have to be able to log into my Google account to get at the data.

I’ve (only) just discovered that read_csv() can load a file straight from a url, so you can load your data from Google Drive like this.

Get a sharing link for your file in Drive that everyone can read. It’ll look like this:

https://drive.google.com/file/d/1gSVUZhh8w-GbJz9yaJVfSv_XmOBPncXPr/view?usp=sharing

Remove the file id and add it to this url instead:

https://drive.google.com/uc?export=download&id=1gSVUZhh8w-GbJz9yaJVfSv_XmOBPncXPr

You can also find Google Drive sharing->download link converters where you can cut & paste your link in. Then you can simply:

import pandas as pd
url = "https://drive.google.com/uc?export=download&id=1gSVUZhh8w-GbJz9yaJVfSv_XmOBPncXPr"
df = pd.read_csv(url)

If you have custom modules stored on drive you can load them in a very similar way.

from urllib.request import urlretrieve
import os
 
def download(url, file):
  if not os.path.isfile(file):
    print("Downloading file:", file)
    urlretrieve(url, file)
    print("Done")
 
url_module = "https://drive.google.com/uc?export=download&id=1KJeTUhMF6hbw1nGbWop5_atYInatLl2k"
download(url_module, "your_module.py")
 
import your_module as lolorcopters