Learning Python - Tutorial #1

Introduction

This is a brief first tutorial for learning Python using Google's Colaboratory.

It will cover loading the package, using a function within the package, and assigning a variable. We will use the numpy package as an example.

Loading the numpy package

numpy is a useful package for data analytics work.

In the code below, numpy is imported and abbreviated as np.

It is a normal convention to load them upfront at the start of the script.

import numpy as np

Exploring the mean function within numpy

Let's check out the mean function in numpy. We can do so by typing np.m in the console below. You can see mean among the list of available functions in numpy.
Screenshot 2022-01-24 at 10.23.26 PM.png

Let's calculate the mean of an array of 1,2,3 using the code below.

np.mean([1,2,3])

Assigning variable

Let's name the variable that comprised 1,2,3 as list_of_nums. Notice the square bracket encapsulating the numbers separated by commas? This is how an array of values can be created.

list_of_nums = [1,2,3]

Problem to solve

To create a new variable called my_mean and assigned the mean of list_of_nums to it.

This is the solution which used what we learn in this tutorial.

my_mean = np.mean(list_of_nums)

The original file is located at: https://colab.research.google.com/drive/1zgTvee6cupneaKrx0G_0lExikzkcHsRV

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now