Bot TutorialsGrok BotChatGPTClaudeGeminiCopilotPerplexityMore botsGuidesArticlesPapers
Topics
CookingHome automationFitnessCreative writingMusic productionCodingIndustrialPros (Professional track)
Search

Part 4 of 12

NumPy and pandas Basics with a Bot: Cheat Sheet

Cheat sheetBy Bot Tutorials · Published · Facts last verified Nov 3, 2026

ML libraries series complete. "Review Your Training Code with a Bot: Checklist" was the finale. See every part in the series hub.

Part 4: shapes, dtypes, broadcasting, missing values and groupby, with real output from NumPy 2.5 and pandas 3.1, and prompts that keep a bot honest.

Video: NumPy and pandas Basics with a Bot: Cheat Sheet (4:00). Narrated from this guide, with the real code and real output we ran. Captions included (caption file). Prefer reading? Everything in the video is in the guide below.

Almost every machine learning library sits on top of NumPy arrays, and most real data arrives as a pandas DataFrame. You don't need to know everything about them, but you do need a handful of ideas: shapes, dtypes, broadcasting, missing values and grouping. This cheat sheet covers those with a short script and its real output, and shows how to get a bot to explain your own data without making things up.

What the bot can and can't do here

It can:

It can't:

Check first, transform second

Before you change data, look at it: shape, dtypes and missing counts. Most bugs are a wrong assumption about one of those three.

The script

import numpy as np, pandas as pd
rng = np.random.default_rng(42)
a = rng.normal(size=(3, 4))
print("shape", a.shape, "dtype", a.dtype)
print("column means", np.round(a.mean(axis=0), 3))
b = np.arange(4)
print("broadcast add row:", (a + b).shape)
df = pd.DataFrame({"part": ["gpu", "cpu", "ram", "gpu"], "price": [499.0, 219.0, None, 649.0]})
print(df.dtypes.to_dict())
print("missing prices:", int(df["price"].isna().sum()))
print(df.groupby("part")["price"].mean().round(1).to_dict())
print(df.dropna().query("price > 300")[["part", "price"]].to_string(index=False))

Real output on our box with NumPy 2.5.4 and pandas 3.1.0:

shape (3, 4) dtype float64
column means [-0.554 -1.065  0.586  0.467]
broadcast add row: (3, 4)
{'part': <StringDtype(storage='python', na_value=nan)>, 'price': dtype('float64')}
missing prices: 1
{'cpu': 219.0, 'gpu': 574.0, 'ram': nan}
part  price
 gpu  499.0
 gpu  649.0

NumPy in five lines

pandas in five lines

Prompts that work

Here are df.shape, df.dtypes and df.head(10) (pasted). Write pandas code to get the mean of price for each part. Don't assume columns I haven't shown. Tell me what happens to missing prices.

These two arrays have shapes (3, 4) and (3,). Why does adding them fail, and what are two ways to fix it? Show the resulting shapes.

The second prompt is a good test of a bot. The right answer explains that broadcasting aligns trailing dimensions, so (3,) doesn't line up with the 4 columns, and suggests reshaping to (3, 1) or using the matching axis.

Common mistakes to watch for

Words you'll see

Knowing these words makes bot answers easier to check, because you can ask exactly what you mean.

Tested vs documented

Where to go next

The next part today uses these arrays to train a first scikit-learn model.

Safety, licensing and privacy: read this before you run anything

This series is about learning and small personal projects with machine learning libraries. A bot is a helper, not an authority.

FAQ

Why does the text column show a StringDtype?

That's what pandas 3.1 reported on our box for a column of strings. Older pandas versions showed object. If a bot tells you to expect object, check your version.

Should I use np.random.seed?

NumPy's docs recommend the Generator interface, created with np.random.default_rng, for new code. That's what our example uses.

Was this tested?

Yes. Every output on this page came from running the script on our box.

Sources

  1. NumPy: Installing NumPy
  2. NumPy: the absolute basics for beginners
  3. NumPy: Random Generator
  4. pandas: Installation
  5. pandas: 10 minutes to pandas

More in this series

  1. Part 1: GPU, Driver and CUDA Compatibility: A Bot-Assisted Check · Guide
  2. Part 2: How Much Memory Does a Model Need? A Data Brief · Data brief
  3. Part 3: Pin Versions and Build Reproducible ML Environments · Walkthrough
  4. Part 4: NumPy and pandas Basics with a Bot: Cheat Sheet (you are here) · Cheat sheet
  5. Part 5: Your First scikit-learn Model, Built with a Bot · Walkthrough
  6. Part 6: PyTorch on the CPU: First Steps with a Bot · Guide
  7. Part 7: TensorFlow and Keras Install Requirements, Explained · Explainer
  8. Part 8: JAX on the CPU: Field Notes with a Bot · Field notes
  9. Part 9: Read Hugging Face Model Cards and Licenses with a Bot · Guide
  10. Part 10: Export a Model to ONNX and Run It: A Deep Dive · Deep dive
  11. Part 11: Read ML Error Messages and Profile Code: Cheat Sheet · Cheat sheet
  12. Part 12: Review Your Training Code with a Bot: Checklist · Checklist

See the ML Libraries with a Bot series hub · Latest on Bot Tutorials

Bot advice can be wrong. We cite official docs; check them yourself before acting, especially for anything involving money, safety or your data.