Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
11 views
unlisted
ubuntu2204
Kernel: Python 3 (system-wide)

Using your Google Drive in Google Collab

One issue with using Google Collab is accessing files in your "Collab Notebooks" directory of your Google Drive. The following examples show how to do this.

# Mount the Google Drive (you will be asked to grant access) from google.colab import drive drive.mount('/GoogleDrive')
Mounted at /GoogleDrive
# Add the 'Colabs Notebooks' directory to the search path for importing # (this only needs to be done once) import sys sys.path.append('/GoogleDrive/My Drive/Colab Notebooks/')
# Import the "linear_fit" function form the file "fiting.py" in the "Collab Notebooks" directory from fitting import linear_fit
import numpy as np # Read from the file "input.txt" in the "Colab Notebooks directory" x, y, yerr = np.loadtxt('/GoogleDrive/My Drive/Colab Notebooks/input.txt', unpack=True) # Write to the file "output.txt" in the "Colab Notebooks directory" np.savetxt('/GoogleDrive/My Drive/Colab Notebooks/output.txt', x)

If you want to include an image file from your Google Drive in a Jupyter notebook, there are instructions at https://medium.com/analytics-vidhya/embedding-your-image-in-google-colab-markdown-3998d5ac2684.