0% found this document useful (0 votes)
61 views

Introduction to Google Colab

Uploaded by

muska07n
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Introduction to Google Colab

Uploaded by

muska07n
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Introduction to Google Colaboratory

(Google Colab)

Dr. Faisal Anwer


Department of Computer Science
Aligarh Muslim University, Aligarh-202002
1
Copyright © Dept of Computer Science, AMU, Aligarh. Permission required for reproduction or display.
Recap of Previous Lecture
• Features of Python

• IDE and Editors

• How to run a python code

• Introduction of Advanced Libraries


Contents
• Introduction to Google Colab

• Features of Google Colab

• How to read Datasets in Google Colab ?


– Importing Kaggle Dataset into Colab
– Downloading and uploading Dataset to Colab
– Read directly through Google Drive

• How to read Github Project in Google Colab?


Introduction
➢ Google Colab is a cloud-based Jupyter notebook
environment from Google Research.

➢ Jupyter is the open source project on which Colab is based.

➢ Colab, or "Colaboratory", allows to write and execute


Python in browser.

➢ Colab helps us get started with our data science journey


with almost no setup.
Introduction
➢ Advantages of Google Colab:
✓Pre-installed data science libraries
✓Easy sharing and collaboration
✓Seamless integration with GitHub
✓Working with data from various sources
✓Seamless integration with Kaggle Datsets
✓Automatic storage and version control
✓Access to hardware accelerators such as GPUs and
TPUs
Google Colab
• Colab notebooks are stored in Google Drive.
• It can be shared similar to Google Docs or Sheets.
• Click on Share button present at the top right of any
Colab notebook to share colab notebooks.
• Mounting Google Drive on Colab allows any code in
your notebook to access any files in your Google Drive.
Google Colab Notebook
• A notebook is a collection of cells.

• Cells contain either explanatory text or executable code and


its output.

• Once the toolbar button indicates CONNECTED, click in


the cell to select it and execute the contents;
Getting Started With Google Colab
• To start working with Colab you first need to log in to your
Google account, then go to this link
https://colab.research.google.com.

• Once you've signed in to Colab, you can create a new


notebook by clicking on 'File' → 'New notebook’,

• On creating a new notebook, it will create a Jupyter


notebook with Untitled0.ipynb and save it to your google
drive in a folder named Colab Notebooks.

• Google Colab allows you to write Python code as well as


text
Working with data from various sources
• Loading data from local machine

• Mounting Google drive to Colab instance


– By clicking on drive icon
– Alternatively, by using the following code:

from google.colab import drive


drive.mount(‘/content/drive')
Access to computer hardware accelerators
GPUs and TPUs

• Goto Runtime and click change runtime. Here you


can select the hardware accelerators.

• If you want to access premium GPUs, you can


purchase additional compute units.

• You can also manage sessions by accessing Runtime


->Manage Sessions. Here you can terminate the other
sessions if need arises.
Reading Kaggle Dataset
Importing Kaggle Dataset into Colab
1. Open your Google Colab Notebook
2. Download and Install the required packages.
pip install opendatasets
3. Visit Kaggle website(www.kaggle.com) and go to your
profile. Next click on account.
4. On the next page an API section will be vissible, where
you will find a “Create New API Token”. Click on it,
and a kaggle.json file will be downloaded. This file will
contain your username and key that will be used in our
next step.
5. Import the opendatasets library and download your
Kaggle dataset by pasting the link on it
import opendatasets as od
import pandas
od.download(" "https://www.kaggle.com/datasets/
camnugent/california-housing-prices" ")
Downloading and uploading Dataset to Colab

1. Visit Kaggle website(www.kaggle.com) and go to


particular dataset. Let say
https://www.kaggle.com/datasets/camnugent/california-
housing-prices/data
2. Download the dataset.
3. Open your Google Colab Notebook
4. Press files present at left bar.
5. Click on Upload to session storage and follow the
instruction.
6. Now, you can read the dataset by executing below code:
import pandas as pd
df = pd.read_csv("/content/housing.csv")
Read directly through Google Drive
1. Visit Kaggle website(www.kaggle.com) and go to
particular dataset.
2. Let say
https://www.kaggle.com/datasets/camnugent/california-
housing-prices/data
3. Download the dataset.
4. Upload the dataset to Google drive
Read directly through Google Drive
5. Open your Google Colab Notebook and mount your google
drive by executing below code

from google.colab import drive


drive.mount('/content/drive’)

6. Once you will execute the above code Google colab notebook
will ask permission to access your Google Drive files, which
you need to provide.

7. Now, you can read the dataset by executing below code:


import pandas as pd
df = pd.read_csv("/content/drive/MyDrive/ABE/housing.csv")
Reading Github Project into Google
Colab
Reading Github Project
• Visit the website of Github https://github.com/

• Sign in to Github using your credentials

• Go the project that you want to access

• Open the google colab file present in the project and press
open in Colab option
Summary
• Introduced Google Colab

• Features of Google Colab

• Reading Datasets in Google Colab

• Reading Github Project in Google Colab

You might also like