Python, NumPy & Pandas Detailed Notes
Beginner to Advanced Study Notes
Author: Generated by ChatGPT
1. Python Basics
Python is a high-level, interpreted programming language. It is easy to learn and widely used in data
analysis, AI, web development, and automation.
Hello World Example:
print('Hello, Python!')
Variables & Data Types:
• int: x = 10 (integer number) • float: y = 3.14 (decimal number) • str: name = 'Alice' (string) • bool: is_true =
True (boolean value) • list: lst = [1,2,3] (ordered collection) • tuple: t = (1,2) (immutable collection) • dict: d =
{'a':1} (key-value pairs)
Operators:
Arithmetic: +, -, *, /, %, ** Comparison: ==, !=, >, <, >=, <= Logical: and, or, not
Conditional Statements Example:
x = 10 if x > 5: print('x is greater than 5') else: print('x is 5 or less')
Loops Example:
for i in range(5): print(i) count = 0 while count < 5: print(count) count += 1
Functions Example:
def add(a,b): return a + b print(add(5,3))
OOP Basics Example:
class Person: def __init__(self,name,age): [Link] = name [Link] = age p =
Person('Alice',25) print([Link],[Link])
2. NumPy Basics
NumPy is a Python library used for numerical computing. It provides fast multidimensional arrays and
mathematical operations.
Import and Array Creation:
import numpy as np arr = [Link]([1,2,3,4,5]) print(arr)
Array Attributes: shape, size, ndim, dtype
Indexing & Slicing Example:
arr[0] # first element arr[1:4] # slice from index 1 to 3
Operations Example:
arr + 5 # add 5 to each element arr * 2 # multiply each element by 2 [Link](arr)
# mean of array
3. Pandas Basics
Pandas is a Python library for data analysis and manipulation, providing two main data structures: Series
(1D) and DataFrame (2D).
Import & DataFrame Creation Example:
import pandas as pd df = [Link]({ 'Name':['Alice','Bob','Charlie'],
'Age':[25,30,22] }) print(df)
Data Inspection Examples:
[Link](), [Link](), [Link](), [Link]()
Selecting Rows & Columns Examples:
df['Age'] [Link][0,'Name'] [Link][1,1]
Filtering & Grouping Example:
df[df['Age']>23] [Link]('Age').count()
4. Exercises
• Python: Write a program to print all even numbers from 1 to 20
• Python: Create a dictionary and print all keys & values
• Python: Define a function to calculate factorial of a number
• NumPy: Create a 2D array of size 3x3 and compute its sum
• NumPy: Slice a 2D array to extract the first row only
• Pandas: Create a DataFrame and filter rows where Age > 22
• Pandas: Compute mean age from the DataFrame
5. Revision Summary
• Python basics: variables, data types, loops, functions, OOP
• NumPy basics: arrays, indexing, slicing, operations, functions
• Pandas basics: Series, DataFrame, reading files, filtering, grouping
• Practice exercises to reinforce learning