Skip to content

← Back to Python Course Foundations

NumPy and Pandas Basics

Learning Objectives

  • Compute mean, median, standard deviation, and variance using NumPy.
  • Create DataFrames from list and dictionary.
  • Access rows/columns with loc and iloc.

Example

import numpy as np
import pandas as pd

arr = np.array([72, 85, 90, 68, 85])
print(np.mean(arr), np.median(arr), np.std(arr), np.var(arr))

data = {"name": ["Asha", "Ravi"], "marks": [88, 92]}
df = pd.DataFrame(data)
print(df.loc[0])
print(df.iloc[:, 1])

Dry Run

  • NumPy computes numeric summaries quickly.
  • loc uses labels, iloc uses positions.

Common Mistakes

  • Mixing label index and integer index in selection.
  • Forgetting to install/import required libraries.

Practice

  1. Read a CSV and print top 5 rows.
  2. Filter students with marks > 80.