Numpy and Pandas in Python
Lecture-18
Instructor Name: Rida Fatima
.
TODAY’S AGENDA:
• Numpy
• Arrays
• Indexing
• Pandas
• Random
.
What is Numpy?
• Numpy is a general-purpose array-processing package. It provides a high-
performance multidimensional array object and tools for working with these
arrays. It is the fundamental package for scientific computing with Python.
.
.
Arrays in Numpy
• A NumPy array is a structured collection of elements of the same data type
stored in a table format.
• The number of dimensions is called the rank and the size along each
dimension is called the shape.
.
Creating a NumPy Array
• NumPy arrays can be created in multiple ways using lists, tuples, or other
sequences. NumPy automatically detects the data type of elements, but the
type can also be defined manually.
.
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.
.
Array indexing 1D
Array indexing 2D
.
Random Numbers in NumPy
• In NumPy, random numbers are generated using the [Link] module
for tasks like simulations, testing, and machine learning.
• You can create random integers, floats, or arrays of random values easily
using functions like rand(), randint(), and random().
.
Intro to Pandas
• Pandas is a powerful Python library used for data analysis, cleaning, and
manipulation. It helps you work with structured data like tables (Excel-style
data) in Python easily.
• It mainly works with two data structures:
• Series (1D data)
• DataFrame (2D table like Excel
.
1. Series (1D Data)
A Series is like a single column.
[Link] (2D Table)
A DataFrame is like a table (rows + columns).
.
Basic Operations
• shape → tells how many rows and columns are in the dataset
• columns → shows all column names
• info() → gives a quick summary (data types, missing values,
memory usage)
• describe() → gives basic statistics like average, min, max, etc.
• DataFrame output → shows the actual table data
THANK YOU