Chapter 2 - NumPy and Pandas
Chapter 2 - NumPy and Pandas
NumPy, Pandas
Chapter - 3
Contents
10
20
30
1-dimensional Array
2-dimensional
array
NOTE: NumPy’s array class is called ndarray. It is also known by the alias array
Creating array using arange()
• NumPy arange() creates an
instance of ndarray with
evenly spaced values and
returns the reference to it.
• Syntax
numpy.arange([start, ]stop,
[step, ], )
Python NumPy ndarray
Objects and Operations
ndarray.ndim
• the number of axes (dimensions) of the array.
ndarray.shape
• This is a tuple of integers indicating the size of the
array in each dimension. For a matrix with n rows and
m columns, shape will be (n,m).
ndarray.size
• the total number of elements of the array. This is
equal to the product of the elements of shape.
Python NumPy ndarray Objects
and Operations
ndarray.dtype
• an object describing the type of the elements in the array.
Example types are numpy.int32, numpy.int16, and
numpy.float64 .
ndarray.itemsize
• the size in bytes of each element of the array. For example, an
array of elements of type float64 has itemsize .
ndarray.reshape:
• Reshape is when you change the number of rows and columns
which gives a new view to an object.
• ndarray.reshape(new shape)
Python NumPy ndarray
Objects/Operations...
Array Indexing, Slicing and Filtering
Broadcasting in NumPy Arrays
• Broadcasting is one of the best features of ndarray.
• It allows us to perform arithmetic operations between arrays of same
shape/different sizes or between a single number and an array.
Numpy Functions
Stacking ndarrys
What is Pandas?
• Pandas is a Python library for data analysis.
• It offers a number of data exploration, cleaning and
transformation operations that are critical in working with
data in Python.
• Commonly used data structures in pandas are:
• Series objects: 1D array, similar to a column in a
spreadsheet
• DataFrame objects: 2D table, similar to a spreadsheet
• Panel objects: Dictionary of DataFrames, similar to sheet
in MS Excel
Pandas Series
• Pandas Series is a one-dimensional labeled array capable of holding data of any
type (integer, string, float, python objects, etc.).
• The axis labels are collectively called index.
Pandas Series...
Accessing element of Series
Pandas DataFrame
It’s a 2 D - size-mutable, potentially heterogeneous tabular data
structure (like table) with rows and columns.
https://www.geeksforgeeks.org/python-pandas-
dataframe/
https://www.learndatasci.com/tutorials/python-pandas-tutorial-complete-introduction-for-
beginners/
Creating Dataframes
Dataframe
Rename column
Creation
DataFrame
Updating row
Dropping
values
rows
Basic Operation on Dataframes
Subsetting Dataframes
subsetting subsetting subsetting Rows
Rows Columns & Columns
Subsetting Dataframes...
subsetting by
subsetting by label position
Filtering Dataframes
References :
https://numpy.org/devdocs/user/absolute_beginners.html
https://datascience.quantecon.org/scientific/numpy_arrays.html
https://www.geeksforgeeks.org/numpy-stack-in-python/
https://www.machinelearningplus.com/python/101-numpy-exercises-python/
https://realpython.com/pandas-dataframe
/#:~:text=%20The%20Pandas%20DataFrame%3A%20Make%20Working%20With%20Data
,that%20you%E2%80%99ve%20created%20your%20DataFrame%2C%20you...%
20More%20
https://www.geeksforgeeks.org/implementing-web-scraping-python-beautiful-soup/?ref=rp