Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

Introduction to NumPy and

pandas

24/11/2021
Fernando Cruz,
Marta Sampaio,
Nuno Alves
Outline
Matrices pandas
◦ What is a matrix? ◦ Series
◦ Matrices operations ◦ Dataframe
◦ Dataframe manipulation
NumPy
◦ Viewing data
◦ Arrays
◦ Indexing and selection
◦ Basic operations
◦ Missing data
◦ Indexing, slicing and iterating
◦ Column operations
◦ Manipulation
◦ Daframe merge
◦ IO
◦ Dataframe grouping
◦ Plotting
What is a matrix?
o Numeric structures organized into rows (n) and columns (m)

o They can be rectangular (n ≠ m) or square (n = m).

o They can be used to represent linear systems.

(2 x 3) Matrix of shape 2 per 3

element
Type of matrices
Name Shape Example Description

Row vector 1 × m A matrix with only one row

A matrix with only one


Column vector n × 1 column

A matrix with the same


Square matrix n × m number of rows and
columns
Matrices operations
Matrices additions and subtractions

Element-wise addition.
Matrices operations
Matrices additions and subtractions

Element-wise subtraction.

One can only add or subtract matrices of the same shape/size


Operações com Matrizes
Multiplying by a number
Matrices operations
Multiplying by another matrix

Multiplying two matrices can only be done if the number of columns (m) of
the first matrix is the same as the number of rows (n) of the second
Matrices operations
Multiplying by another matrix

Matrices multiplication is not commutative!


(except for some square matrices)
Matrices operations
Multiplying by another matrix

(2 x 2) (2 x 2)

AxB=
(2 x 2)
x
Matrices operations
Multiplying by another matrix

4 x 3 + (-1) x 6 + 5 x (-2) 12 - 6 - 10 -4
AxB= = = 49
3 x 3 + 6 x 6 + (-2) x (-2) 9 + 36 + 4
Matrices operations
Matrices division
(This concept is not correct, as we must multiply the matrix for the inverse!)

A : B = A x B-1
Matrices operations
Transpose

Transposing a matrix consists of switching rows by columns


NumPy and pandas
Let’s implement this in Python

The fundamental package for scientific The fundamental package for data analysis and
computing with Python manipulation in Python
Hands on
1. Load the datasets 1 and 2 using pandas.

2. Perform a descriptive analysis of both datasets.

3. Handle missing data of both datasets.

4. Merge both datasets using the Accession column as key.

5. Make a scatter plot for the first two columns of the resulting dataset from 4.

You might also like