Ravindra BagaleCourses & study guides

4. NumPy Essentials

4.3 Why pandas Sits on NumPy

A pandas Series exposes .to_numpy():

import pandas as pd
s = pd.Series([9, 12, 11, 14, 18], name="delivery_mins")
arr = s.to_numpy()
print(type(arr), arr.mean())

You rarely write NumPy-first analysis in this course, but when pandas is slow or you need matrix maths, remember the array underneath.

Practice task

Create a NumPy array of fictional delivery minutes [9, 12, 11, 14, 18, 10, 8, 13]. Print min, max, mean and the count of trips under 12 minutes using vectorised comparison (mins < 12).sum().

Thodkyaat sangaycha tar (quick recap)

  • np.array, shape, dtype, vectorised * and .sum()
  • Prefer numeric dtypes for money and measures
  • pandas Series/DataFrame wrap NumPy arrays

Samajla ka? Aata pudhe jaauya pandas DataFrames and Series.