University Muhammed VI Polytechnic (UM6P)
NUMPY AND
PANDAS
Presented by:
Ridwan Ibidunni
[Link] Date : 27 - 04 - 24
INTRODUCTION
Numpy Pandas
01 NumPy, short for Numerical Python, is an essential 02 Pandas is a fast, powerful, and flexible open-source
package for numerical computing in Python. It offers library for data analysis and manipulation. Built on
support for large, multi-dimensional arrays and top of NumPy, it provides intuitive data structures,
matrices, as well as a range of mathematical functions high-performance tools, and analysis capabilities,
for efficient array operations. making it essential for data wrangling and
exploration in Python.
[Link]
NUMPY
NumPy is a fundamental package for numerical computing in Python,
serving as the cornerstone of numerical and scientific computing. Its
primary data structure, ndarray, is a powerful N-dimensional array
object designed for fast and space-efficient data storage and
manipulation. Key features include a wide range of mathematical,
logical, and statistical operations on arrays, seamless integration
with other languages such as C/C++ and Fortran, making it ideal for
numerical computations and data analysis.
[Link]
NUMPY ARRAY
IMPLEMENTATIONS
[Link]
CREATING
NUMPY ARRAY
The most basic form of a NumPy array is a one-dimensional
(1-D) array, which can be created using the array() function
with a list as its argument.
[Link]
CREATING
NUMPY ARRAY
Another method of creating a NumPy array is by using the
arange() function, which is similar to the range() function
used for lists. It takes three arguments: the starting value,
the end value (one less than the specified value), and the
step size for incrementing or decrementing.
[Link]
CREATING
NUMPY ARRAY
The linspace() function allows us to create an array with a
specified number of elements between a specified range,
including both the starting and ending values. This is different
from the arange() function, as linspace() returns an array with
a specified number of elements evenly spaced within the
specified interval.
[Link]
NUMPY ARRAYS WITH
FIXED ELEMENTS
NumPy offers specific functions like zeros(), ones(), and full() to
initialize arrays with fixed values. These functions take the
desired size (number of elements) of the array as an
argument.
[Link]
MULTIDIMENSIONAL
ARRAY
Arrays can also be multidimensional, similar to tables with more
than one row and one column. To create a multidimensional
array, each row of the array is represented as a list, with each
element in the list corresponding to a column. These lists are
then separated by commas. The rows and columns must be
enclosed in outer square brackets as well.
[Link]
NUMPY ARRAY
DIMENSIONS
The size function is used to determine the number of elements
in an array. The shape function returns the number of rows and
columns in an array, while the ndim function is used to find the
dimensionality (number of dimensions) of an array.
[Link]
ARRAY MATH
OPERATION
NumPy enables you to perform element-wise addition,
subtraction, multiplication, and division effortlessly on both 1-D
and multidimensional arrays. These operations use standard
mathematical symbols: +, -, and *. Unlike Python lists, where
addition results in concatenation, NumPy operations work
element-wise.
[Link]
BROADCASTING IN
NUMPY ARRAY
NumPy's broadcasting feature enables it to perform arithmetic
operations on arrays of different shapes. When conducting
element-wise operations like addition, subtraction, and
multiplication on arrays with different shapes, NumPy
automatically broadcasts the arrays to have compatible shapes.
This facilitates element-wise operations without requiring the
arrays to have the same shape. For instance, if you have a 1D
array of shape (3,) and want to add a scalar value to it, NumPy
will automatically broadcast the scalar value to match the
shape of the array (3,), allowing element-wise addition to be
performed seamlessly.
[Link]
PANDAS
Pandas, built on top of NumPy, is a powerful open-source data
analysis and manipulation library for Python. It offers intuitive data
structures like DataFrame and Series, along with tools for indexing,
slicing, merging, reshaping, and aggregating data. With support for
various file formats including CSV, Excel, SQL databases, and JSON,
Pandas is essential for data wrangling and exploration in Python.
[Link]
PANDAS
IMPLEMENTATION
[Link]
CREATING
SERIES
A Series is an enhanced one-dimensional array. It goes
beyond supporting zero-based indices; it also allows for
custom indexing, including non-integer indices such as
strings.
[Link]
CREATING
SERIES
The Series provides many methods for common descriptive
statistical tasks, including count, mean, min, max, std
(standard deviation), and more.
[Link]
CREATING
DATAFRAMES
A DataFrame is an enhanced two-dimensional array. Like
Series, DataFrames can have custom row and column
indices, along with additional operations and capabilities
that make them more convenient for many data science-
related tasks.
[Link]
CREATING
DATAFRAMES
In Pandas, you can access each column by specifying the
column name inside square brackets after the DataFrame
name, as shown in this image
[Link]
CREATING
DATAFRAMES
According to the Pandas documentation, using [] to access
DataFrame items is not the most optimized approach, as it
creates a copy of the data, which can lead to logical errors
when assigning new values. Instead, it's recommended to
use the loc and iloc attributes for accessing DataFrame
items. You can access a row by its label using the loc
attribute or by its index using the iloc attribute.
[Link]
CREATING
DATAFRAMES
Slicing can be used to obtain a portion of the table. Some of
these are implemented in this image
[Link]
CREATING
DATAFRAMES
More examples on Slicing
[Link]
CREATING
DATAFRAMES
More examples on Slicing
[Link]
CREATING
DATAFRAMES
Finally, you can obtain a quick summary of its main
descriptive statistics using the describe() function using the
same dataset from the previous slides, as shown in this
image
[Link]
MACHINE LEARNING REPO
[Link]/aljebraschool
To stay updated with my
work, visit my website.
[Link]
ALJEBRASCHOOL
ALJEBRA SCHOOL TWITTER LINKEDIN FACEBOOK
BLOG
[Link] [Link]/aljebraschool [Link]/in/aljebraschool [Link]/aljebraschool
LINK UP
Follow us on all social media for more updates!!!
...ideas rule the world...