Main Headline Postgraduate Studies Smart Tech Corner

Kick-starting data science using Google Colaboratory

中文摘要 / Summary in Chinese

IFTM has launched its new postgraduate programmes in Smart Technologies in Hospitality and Tourism in August 2022. Twenty-four students enrolled in the two-credit Introduction to Technology in Tourism course, with its main aim to introduce coding and computational thinking using the Python language to students. Python is an excellent programming language for absolute beginners. With a relatively shallow learning curve, rich sets of libraries and packages, as well as a global community with millions of developers and active amateur programmers, Python provides this introductory language to newbie programmers who can then be able to build prototypes and tools swiftly allowing them to obtain immediate results.

There are a variety of distributions of the Python language and their runtime environments. To cope with teaching and learning at several different locations—remote classes, Windows PCs and Mac computers in lab respectively during the same teaching slot, Dr. Simon Lei decided to choose Google Colaboratory to teach Python coding. Colab does not require upfront setup or installation; it is ready to use as long as one has a web browser and a Google account to sign in. Colab provides a Jupyter-like notebook environment on a remote virtual machine. Through the connection to the cloud-based Python 3 Google Compute Engine Backend, one can use the cloud-based RAM and disk space to run their programs, without sacrificing the computing resources on their own PC or laptop. The option of using a GPU on Colab is also available for hardware acceleration when intensive computation is required. The basic plan of Colab is free of charge.

https://colab.research.google.com

It is also suggested for the users to use Google Drive along with the Colab. In that sense, users not only can easily extract or go through files from the Drive, but it also allows Python programs to manage and get the access ready at all times. To help readers get the most out of the Google ecosystem, the following exemplifies how to connect one’s Google Drive under the Google Colab environment.

from google.colab import drive

drive.mount('/drive', force_remount=False)

PATH = '/drive/My Drive/'

filename = 'myfile.csv' # assuming that the file is uploaded to Google Drive

with open(PATH + filename, encoding='utf-8') as fin:

  pass     # the actions are omitted here

fin.close()

In addition, it is relatively simple to make API calls to make queries on Google Books API portal. The following example illustrates on how to make a query on “Travel Photography” books via an API call:

import requests

url = 'https://www.googleapis.com/books/v1/volumes'

myParams = {'q': 'Travel Photography', 'maxResults': 10, 'projection': 'lite'}

r = requests.get(url, params=myParams)

data = r.json()

for row in data['items']:

  print(row['volumeInfo'].get('title').upper(), end="")

  print(' (' + str(row['volumeInfo'].get('subtitle')) + ')')

“I think Google Colab is really cool as it is convenient and efficient,” said Amy Fong, a student of the Smart Tech Cohort 2022. Colab can greatly facilitate programmers to collaborate on the same project even though they are physically apart. “I can easily share with others and grant different levels of access, i.e., view and editing, so I can work together with my partner without geographic location limits,” agreed by Helen Lam, another student from the same cohort. The only shortcoming of using Google products is its inaccessibility in the Mainland. Under such conditions, students are advised to carry out alternative solutions, such as setup and installation of some Python distribution on their own devices, running Python in offline mode. “To me, the advantages of Google Colab still largely outweigh its disadvantages,” remarked Amy. Last but not least, most of the commonly used libraries and packages are ready to be imported in Google Colab, without the need for installation explicitly; this can greatly save novice programmers’ time and effort, thus helping make Python programming less daunting and more enjoyable.

 

By Dr. Simon Lei, Assistant Professor