Colab : Free Cloud Platfrom from Google


Google Colab, a cloud-based platform, streamlines Python programming and data science projects. It stands out for utilizing Google's cloud infrastructure, offering powerful computational resources without needing local installation.

With just a Google account, it provides a free and accessible environment for everyone from beginners to advanced data science practitioners.

Advantage of using Colab the colud platform for Python 🔝

  1. Resource Availability:
    • Computational Power: Colab provides access to powerful GPUs and TPUs.
    • Memory: Colab allows for more memory, useful for handling large datasets and computations.
  2. Free Access to GPU and TPU:
    • Colab provides free access to GPU and TPU resources, beneficial for machine learning tasks.
  3. Collaboration and Sharing:
    • Colab facilitates real-time collaboration and easy sharing of notebooks.
    • Multiple users can work on the same notebook simultaneously.
  4. Integration with Google Services:
    • Colab integrates seamlessly with Google Drive and other Google services.
  5. Pre-installed Libraries and Packages:
    • Colab comes with pre-installed popular Python libraries and packages.
  6. No Installation Required:
    • Colab is accessed through a web browser, eliminating the need for local installations.
  7. Automatic Saving and Version History:
    • Colab automatically saves work to Google Drive and provides version history.
  8. Easier Access to Data:
    • Colab allows seamless access to data stored in cloud services.
  9. Learning and Exploration:
    • Colab is a great platform for learning and exploration. It is consistently accessible and instantly responsive the moment you initiate or embark on your journey.
    • Beginners can start coding without worrying about environment setup.

Colab is Google Cloud based integrated development environment (IDE) for Python and Machine Learning.

Python libraries ( including Pandas , Numpy ) are already available and you only have to import them to start using. You need one google account to start using colab.

Adding Colab to your Google drive 🔝


Free to use Python : installing libraries plotting graphs and learning commands #colab #python


Inside the google drive click New
adding colab to google drive
New > More > Google Colaboratory 
If this for first time you are using Colab then you need to add this App to your drive.
New > More > Connect More Apps
In new window search for Colab and add this to your drive.

You can share your Juytor notebook files through colab platform. Keep your files in google drive and share them with others.
Open a file or upload or import from github

Downloading files by using wget 🔝

We can collect files by using URL. These files will be available during runtime ( session )only.
# download my_db.db SQLite Database from plus2net.com
!wget https://www.plus2net.com/python/download/my_db.db
# !wget https://www.plus2net.com/python/download/student.xlsx # Excel file download
# !wget https://www.plus2net.com/python/download/student.csv # CSV file download 

Version of Python in Colab 🔝

Execute this line , it will display the version of python
!python --version

Upload and download file from local system to colab 🔝

To upload any file from local system use this code.
from google.colab import files
uploaded = files.upload()
Here uploaded is a dictionary.

To download any file from colab to local system.
files.download('fish-market.jpg')
To create a file and download.
fob=open('data1.txt','w')
fob.write("this is a new text just written")
fob.close()
files.download('data1.txt')

Adding CSV or Excel files to your code. 🔝


Upload Excel or CSV file in google drive and connect from Colab Python platform using mount drive

We can keep our CSV or Excel files in google drive and use it in our Colab platform.
  1. Upload your CSV or Excel file to any folder in google drive. We created one folder inside our Colab Notbooks folder and named it as downloads. You can give your own name to the folders.
  2. Now you have to mount the drive to your colab file. Run this code.
  3. from google.colab import drive
    drive.mount('/content/drive')
    You will be shown one link and below it there will be an text box asking for authorization code. Visit the link and collect ( copy ) your authorization code. You must be already logged in to your gmail account to get the code.
    Paste the code inside textbox and then press enter.
    Now your drive is mounted.

  4. Colab Drive Mounting
    In your left panel you can see drive icon. Expand the directory structure to reach and select your file you want to use. Right click and use copy path.
    Now use this path to create a variable to use in our read_excel() or read_csv() functions.
    import pandas as pd
    path='/content/drive/My Drive/Colab Notebooks/downloads/my_file.xlsx'
    my_data = pd.read_excel(path)
Connecting to CSV file on network.
!wget https://raw.githubusercontent.com/adeshpande3/Pandas-Tutorial/master/RegularSeasonCompactResults.csv

Checking & Installing libraries in Colab 🔝

Installing Pytrends in google colab platform
Check if our required library is already available.
%pip freeze
If not available then install the same. Pytrends is an unofficial google trends api to get the data from google trends.
Here is one more code to check Availability of libraries
import imp
try:
    imp.find_module('reportlab') # check reportlab library for PDF creation
    found = True
except ImportError:
    found = False
print(found)
!pip install pytrends

Useful Google Colab Commands & Their Uses 🔝

Here's a list of common commands used in Google Colab, including shell commands, magic commands, and built-in utilities.

Command Use / Purpose
!pip install package_nameInstall a Python package into your environment
!apt-get install xyzInstall system-level Debian-based packages
!lsList files and folders in the current directory
!pwdPrint current working directory
!cd folder_nameChange directory (temporary in shell, not persistent)
%cd /path/to/dirPersistently change the working directory
!rm filenameDelete a file from the file system
!mkdir folder_nameCreate a new directory
!cp source destCopy files or folders
!mv old_name new_nameMove or rename a file/folder
!wget urlDownload files from a given URL
!curl urlDownload content using curl
!sleep 5Pause execution for 5 seconds
!command &Run a shell command in the background
!nvidia-smiDisplay GPU status (for GPU-enabled sessions)
!pip listList all installed Python packages
!pip freezeList installed packages in requirements.txt format
!pip show packageShow details of a specific installed package
%%timeMeasure the execution time of a cell
%%captureSuppress output from a cell
files.upload()Upload files from your local system
files.download('file')Download a file to your local machine
from google.colab import drive
drive.mount('/content/drive')
Mount Google Drive to Colab
from google.colab import filesImport module to use file upload/download features
!python script.pyRun a Python script from the Colab file system
!echo 'Hello'Print output using shell syntax

Tip: Use ! for shell commands, % for line magics, and %% for cell magics.


Interactive Widgets in Colab

Enhance your Google Colab notebooks using ipywidgets for dynamic user interfaces including sliders, buttons, inputs, and progress bars—all styled with Bootstrap for better readability.

Read Full Guide

🔧 AI Features in Google Colab for Code Assistance 🔝

  1. Code Completion (AI-Powered)
    Google Colab now includes AI-based autocompletion (similar to Copilot), suggesting code as you type. It understands context, variable names, and patterns from the notebook to suggest relevant lines of code.
  2. Code Generation from prompt
    You can write a natural language prompt like create a bar chart from the given data in sqlite database and the AI will generate the corresponding Python code.
  3. Context-Aware Code Suggestions
    Based on the code written above, Colab AI suggests functions, parameters, and data manipulation snippets tailored to your current context.
  4. Debugging Assistant
    When an error occurs, the Colab AI agent can explain the traceback in simple language, suggest possible fixes, and even generate corrected code snippets.
  5. Ask AI (Data Science Agent)
    Located in the sidebar, this lets you type natural language questions like:
    • “Plot the distribution of column X”
    • “Find outliers in my dataset”
    • “What is the correlation between A and B?”
    The AI responds with code you can run directly.
  6. Explain Code Blocks
    Right-click on any code cell and choose "Explain Code" to get a human-readable summary of what the code does. Useful for beginners or reviewing shared notebooks.
  7. Bug Fix Suggestions
    If your code fails, Colab AI might show a suggestion like: "Did you mean df['column_name'] instead of df.column_name?"
  8. Natural Language to Chart/Plot
    You can say “create a line chart of monthly revenue” and Colab will write matplotlib/seaborn code based on your data.
  9. Code Snippet Injection
    With context-aware insertions, Colab suggests full blocks of reusable code (e.g., data cleaning functions, visualizations, model evaluation).
  10. Auto Imports & Fixes
    Colab often detects missing imports and suggests the correct ones, like “Import pandas as pd” if you’re using a DataFrame but forgot the import.
Colab AI suggesting missing imports


AI tool Data Science Agent at Colab platform to analyze Stackoverflow survey data

💡 Try it yourself — no coding required!

You can explore all the SQL query solutions interactively using the Google Colab Data Agent by simply typing your questions ( List of Queries for Student table is here ) in plain English.

Open Colab Notebook on GitHub

Using SQLite in Colab 🔝

We can learn SQLite database management tools without installing any software of libraries by using google colab. SQLite is a file based database so it can be uploaded and placed in google drive. From Colab platform we can connect to SQLite database by using available libraries.
Without installing use SQLite database from google Drive by using Colab.
Pandas DataFrame to SQLite table using Google Colab platform.
Displaying Image from SQLite database in Google colab
From SQLite database table to Excel page and vice versa in Google colab platform
Creating SQLite database table using today's date as base in Google colab platform

Creating PDF files at Colab 🔝

We can create pdf documents by using dynamic data and images taken from SQLite database table.
Generate PDF files at Google colab platform


Introduction to Google Colab, the cloud based platform for working on Python programs

Using Secrets in Google Colab 🔝

How to Store API Keys & Passwords Securely in Google Colab (Secrets Feature Explained) #colab

Google Colab provides a Secrets feature to securely store sensitive data like API keys or credentials. These values are encrypted and not visible when sharing notebooks.

Colab Secrets feature

To add a secret, use the key icon on the left sidebar, name your secret (e.g., OPENAI_API_KEY), and enter its value. Toggle access for each notebook as needed.


Adding secret keys or credentials

You can retrieve a secret in your notebook using:

from google.colab import userdata
api_key = userdata.get('OPENAI_API_KEY')

To use the secret as an environment variable:

import os
os.environ['OPENAI_API_KEY'] = userdata.get('OPENAI_API_KEY')
Secrets in Google Colab are stored at the account level, so once you add a secret, it is available to all your notebooks under the same Google account.

However:
  1. You must explicitly toggle access for each notebook in the Secrets panel.
  2. This ensures that even though the secret exists globally in your account, only the notebooks you authorize can use it.

This keeps your keys hidden and secure while enabling seamless integration with APIs.

Using Gemini API at Colab platform to create AI tools Gemini managing Images
Using .ipynb files as module and Docstrings in Colab

Download and Install Python Learn Python basics through ONLINE classes
Explore the Best Python IDEs for Your Development Journey

Podcast on Python Basics in Hindi Language


Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer