Google Colab Tips and Tricks

Qiusheng WuQiusheng Wu
2 min read
  1. Scratchpad Notebook: https://colab.research.google.com/notebooks/empty.ipynb
  2. Open Notebooks from GitHub: simply replace github.com with githubtocolab.com. It will redirect you to a Colab notebook.
  3. Timing Execution of Cell: hover over the cell run icon and you will get an estimate of the execution time taken
  4. Run part of a cell: Click Runtime -> Run Selection button or using the keyboard shortcut Ctrl + Shift + Enter
  5. Most commonly used shortcuts:
    • Run cell (Ctrl + Enter)
    • Run cell and add new cell below (Alt + Enter)
    • Run cell and goto the next cell below (Shift + Enter)
    • Comment current line (Ctrl + /)
  6. Jupyter Notebook Keyboard Shortcuts: Click Tools -> Keyboard shortcuts or Just add Ctrl + M before whatever keyboard shortcut you were using in Jupyter. For example
    • add a cell above (Ctrl + M + A)
    • Add a cell below (Ctrl + M + B)
    • Change cell to code (Ctrl + M + Y)
    • Change cell to markdown (Ctrl + M + M)
  7. Jump to Class definition: press Ctrl and then clicking a class name
  8. Run bash commands:
    • Download dataset from the web with !wget <ENTER URL>
    • Install libraries with !pip install <LIBRARY>
    • Clone a git repository with !git clone <REPOSITORY URL>
    • Change directory with !cd
  9. Mount your Google Drive to Colab:
    from google.colab import drive
    drive.mount('/content/gdrive')
    
  10. To upload a file (or several) from your computer, run:
    from google.colab import files
    files.upload()
    
  11. To download a file, run:
    from google.colab import files
    files.download('path/to/your/file')
    
  12. Run R programs in Google Colab: You can use R programming language in Google Colab by going to https://colab.to/r. It will open a new notebook with R set as the kernel instead of Python.
  13. “Open in Colab” Badge: You can add a ‘Open in Colab’ badge to your README.md or jupyter notebooks using the following markdown code: Open In Colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/notebooks/basic_features_overview.ipynb)
  14. Run Rust programs in Google Colab: Go to https://colab.to/rust. Then rust the first cell. Reload the page. Skip the first and run other cells, or write your own codes.

References:

3
Subscribe to my newsletter

Read articles from Qiusheng Wu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Qiusheng Wu
Qiusheng Wu

Dr. Qiusheng Wu is an Associate Professor in the Department of Geography & Sustainability at the University of Tennessee, Knoxville. He is also an Amazon Visiting Academic and a Google Developer Expert (GDE) for Earth Engine. His research interests include geospatial data science, remote sensing, and environmental modeling. Dr. Wu is particularly interested in utilizing big geospatial data and cloud computing (e.g., Google Earth Engine, Microsoft Planetary Computer, Amazon Web Services) to study environmental change, especially surface water and wetland inundation dynamics. His research has been funded by NASA, USDA, and the Department of Defense. Dr. Wu is an advocate of open science and reproducible research, having developed and published various open-source packages for advanced geospatial analysis and data visualization, such as geemap, leafmap, lidar, and segment-geospatial. Check out his open-source projects at https://open.gishub.org