1B Python and Notebook
1B Python and Notebook
You may be wondering why popularity should be enough of a reason to use a language. Having a large community of
Python users means you are likely able to get help from others when you ask. One consequence of the language being
popular is that you will find that there is a Python library you can import to help accomplish your analytical or machine
learning goals without writing all your code from scratch. This course utilizes many Python libraries including NumPy,
SciPy, pandas, matplotlib, seaborn, and Scikit-Learn as well as the deep learning framework TensorFlow.
What are Notebooks? In this course, we will use Colab Notebooks which are similar to Jupyter Notebooks except they are
freely hosted by Google so you don't have to install anything on your computer. Both have the file extension of .ipynb.
Notebooks can contain both code and rich text elements, such as figures, links, and equations. The reason why it is
important to not just have code but also text explaining your code and your results is that a lot of data science is about
communicating what the data means to people. While we will not use Python scripts as much in this course, it is important
to be aware of them as they are common in the field and on the job. Python scripts are just text files (.py files) of code that
runs sequentially all the way through the file, which is a benefit of writing code in scripts rather than in notebooks. When
running a notebooks, it can sometimes be tempting to run cells out of order or re-run cells. Be careful of this, as it can
mess up your code or change your results.
Colaboratory, or "Colab" for short, allows you to write and execute Python interactively in your browser.
Like any tool, there are advantages and disadvantages to using Google Colab.
VJDBARAYUGA - 1 | P a g e
DATA VISUALIZATION 01/01/2023
Advantages
1. You don't have to install anything locally on your computer.
2. It comes with a collection of many open source packages (NumPy, scikit-learn, scipy, and pandas to name a few).
3. Provides browser-based Jupyter Notebooks which allows for easy sharing and collaboration.
4. Store notebooks on Google Drive.
5. Notebooks can be shared easily.
6. Free access to GPUs.
Disadvantages
1. Google owns Colab.
2. While it has always been free, it could in the future not be.
3. If it isn't in future, it is easy to switch to other tools.
4. You need a google account to use.
5. Data loading can be more difficult than if you installed python on your computer.
6. Only 1 GB or so of RAM is available.
We will do our work in Google Colab for this course, so make sure you familiarize yourself with it as soon as
possible so you can get started with your coding!
VJDBARAYUGA - 2 | P a g e
DATA VISUALIZATION 01/01/2023
You will then enter the page for your new Google Colab file
From here, you can share your Google Colab file with others using the Share button on the top right-hand corner or start
coding!
VJDBARAYUGA - 3 | P a g e
DATA VISUALIZATION 01/01/2023
The hotkeys on Colab and that on Jupyter notebooks are similar. These are some of the useful ones:
But there’s also one extra that’s pretty useful that lets you only run a particular selected part of the code in a cell:
Just like the Jupyter notebook, you can also write text with Markdown cells. But Colab has an additional feature that
automatically generates a table of contents based on your markdown content, and you can also hide parts of the code
based on their headings in the markdown cells.
If you run Jupyter on your own computer, you have no choice but to use the CPU from your computer. But in Colab, you
can change the runtime to include GPUs and TPUs in addition to CPUs because it is executed on Google’s cloud. You
can switch to a different runtime by going to Runtime ▷ Change runtime type:
VJDBARAYUGA - 4 | P a g e
DATA VISUALIZATION 01/01/2023
You can then select from the different hardware accelerators to equip your environment with.
VJDBARAYUGA - 5 | P a g e
DATA VISUALIZATION 01/01/2023
Unlike your own computer, Google Colab does not provide you with a terminal to enter commands to manage your Python
environment. To install Python libraries and other programs, we can use the ! character to run shell commands just like in
Jupyter notebooks, e.g. !pip install numpy (but as we’ll see later on, Colab already comes pre-installed with a lot of the
libraries we’ll need, such as NumPy)
Now that we know how to set up our Colab environment and start running some code, let’s do some exploration of the
environment!
VJDBARAYUGA - 6 | P a g e