RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /Python for AI — Zero to Useful
  6. /Ch. 14
Python for AI — Zero to Useful

14. Pandas DataFrames

Chapter 14 of 36 · 20 min
KEY INSIGHT

DataFrames are tables with named columns. Chain operations: `df[df["col"] > value]["other_col"]`. Use `inplace=True` when you want to modify the original DataFrame; otherwise, assign to a new variable.

Creating DataFrames

import pandas as pd

# From a dictionary
df = pd.DataFrame({
    "model": ["gpt-4", "gpt-3.5-turbo", "claude-3", "llama-2"],
    "context_window": [8192, 16385, 200000, 4096],
    "cost_per_1k": [0.03, 0.002, 0.015, 0.0]
})

print(df)

Basic Operations

print(df.head(2))           # First 2 rows
print(df.shape)             # (4, 3)
print(df.columns)          # Column names
print(df.dtypes)           # Data types

# Descriptive statistics
print(df.describe())

Selecting Columns

# Single column (returns Series)
models = df["model"]

# Multiple columns (returns DataFrame)
subset = df[["model", "cost_per_1k"]]

# Column operations
df["cost_per_1m"] = df["cost_per_1k"] * 1000

Selecting Rows

# By position
print(df.iloc[0])          # First row as Series

# By condition
expensive = df[df["cost_per_1k"] > 0.01]
print(expensive)

Adding and Removing Columns

# Add calculated column
df["affordable"] = df["cost_per_1k"] <= 0.01

# Remove column
df.drop("affordable", axis=1, inplace=True)

# Rename columns
df.rename(columns={"cost_per_1k": "cost"}, inplace=True)

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

Create a DataFrame of AI models with columns for name, provider, context window, and cost. Filter to models with context > 10K tokens and add a column showing cost per million tokens.

← Chapter 13
Pandas Series
Chapter 15 →
Data Cleaning with Pandas