Module 5
Data Processing using Numpy
and Pandas
Numpy: Array Operations – Mathematical Functions - Pandas: Handling
Files - Creating Dataframes – Data Cleaning – Filtering – Selection –
Grouping – Sorting – Aggregation – Merging.
MATPLOTLIB – PLOTTING LIBRARY
• Line plot to visualize the data
3 Presentation title
MATPLOTLIB – PLOTTING LIBRARY
4 Presentation title
OVERVIEW OF NUMPY
• NumPy is a Python library used for working with arrays.
• NumPy was created in 2005 by Travis Oliphant.
• NumPy stands for Numerical Python.
It is a powerful library used for:
•Working with arrays (lists of numbers, but faster and more efficient)
•Doing mathematical operations easily
•Handling matrices, statistics, and linear algebra
USE OF NUMPY
• In Python we have lists that serve the purpose of arrays, but they are
slow to process.
• NumPy aims to provide an array object that is up to 50x faster than
traditional Python lists.
• The array object in NumPy is called ndarray, it provides a lot of
supporting functions that make working with ndarray very easy.
• Arrays are very frequently used in data science, where speed and
resources are very important.
• Installation of NumPy
• In the command prompt type the following command for numpy
installation,
>pip install numpy
Once NumPy is installed, import it in your applications by adding the
import keyword:
NUMPY ARRAYS
• Create a NumPy ndarray Object
• NumPy is used to work with arrays. The array object in NumPy
is called ndarray.
• We can create a NumPy ndarray object by using the array()
function.
• To create an ndarray, we can pass a list, tuple or any array-like
object into the array() method, and it will be converted into an
ndarray:
Example
• Use a tuple to create a NumPy array:
DIMENSIONS IN ARRAYS
• A dimension in arrays is one level of array depth (nested arrays).
nested array: are arrays that have arrays as their elements.
0-D Arrays
0-D arrays, or Scalars, are the elements in an array. Each value in an array is
a 0-D array.
Example
Create a 0-D array with value 42
1-D ARRAYS
• An array that has 0-D arrays as its elements is called uni-dimensional
or 1-D array.
• These are the most common and basic arrays.
Example
• Create a 1-D array containing the values 1,2,3,4,5:
2-D ARRAYS
• An array that has 1-D arrays as its elements is called a 2-D
array.
• These are often used to represent matrix or 2nd order tensors.
Example
• Create a 2-D array containing two arrays with the values 1,2,3
and 4,5,6:
3-D ARRAYS
• An array that has 2-D arrays (matrices) as its elements is called
3-D array.
• These are often used to represent a 3rd order tensor.
Example
• Create a 3-D array with two 2-D arrays, both containing two
arrays with the values 1,2,3 and 4,5,6:
• NumPy Arrays provides the ndim attribute that returns an integer
that tells us how many dimensions the array have.
Example
• Check how many dimensions the arrays have:
NUMPY ARRAY INDEXING
• Array indexing is the same as accessing an array element.
• You can access an array element by referring to its index number.
• The indexes in NumPy arrays start with 0, meaning that the first
element has index 0, and the second has index 1 etc.
ACCESS 2-D ARRAYS
• To access elements from 2-D arrays we can use comma
separated integers representing the dimension and the index
of the element.
ACCESS 3-D ARRAYS
• To access elements from 3-D arrays we can use comma
separated integers representing the dimensions and the index
of the element.
SLICING ARRAYS
• Slicing in python means taking elements from one given index to another given
index.
• We pass slice instead of index like this: [start:end].
• We can also define the step, like this: [start:end:step].
• If we don't pass start its considered 0
• If we don't pass end its considered length of array in that dimension
• If we don't pass step its considered 1
SLICING
SLICING 2-D ARRAYS
THANK YOU