Pandas & NumPy for ML — ML Technical Interview Questions & Answers
The data-wrangling foundation beneath most ML pipelines.
Pandas & NumPy for ML
- Simple meaning: NumPy is arrays and maths (X as a matrix). pandas is tables (CSV → DataFrame): filter rows, fill NA, new columns. Almost every sklearn tutorial starts here.
- Picture: pd.read_csv('marks.csv'); df['hours']; train_test_split(df[['hours','att']], df['pass']). Values go to NumPy under the hood.
- Learn: loc/iloc, groupby, missing data, astype. Don’t fight sklearn with nested Python lists for 10,000 rows.
- Trap: SettingWithCopy warnings ignored until y is wrong. Trap: including the label column inside X.
Technical Interview Tip: CSV → pandas clean → X, y arrays → sklearn.
Code Examples for Pandas & NumPy for ML
Pandas & NumPy for ML — working example
# PCA-style intuition: project 2D → 1D by a direction vector
points = [(1.0, 1.0), (2.0, 2.0), (3.0, 2.8)]
# unit direction along y = x
ux, uy = 0.7071, 0.7071
proj = [x * ux + y * uy for x, y in points]
print([round(v, 3) for v in proj])
# Tiny ensemble: average two model votes
votes = [1, 0, 1]
v2 = [1, 1, 1]
ens = [1 if a + b >= 2 else 0 for a, b in zip(v1, v2)]
print(ens)Pandas & NumPy for ML — dim reduction compresses features; ensembles combine models; deep nets/RL/NLP are specialized families — practice the core math idea first.
How to Explain Pandas & NumPy for ML to an Interviewer
pandas vs NumPy?
Tables vs numeric arrays
First lines of a lab?
read_csv pick columns split fit