pyai.docs

Data & Math › 9 of 14

Pandas for Data Wrangling

Load, clean, and aggregate tabular data.

python
import pandas as pd

df = pd.read_csv("train.csv")
df.info(); df.describe()

df = df.dropna(subset=["label"])
df["age"] = df["age"].fillna(df["age"].median())
df = pd.get_dummies(df, columns=["city"])

df.groupby("label")["score"].agg(["mean", "count"])
Tip: Use .loc[rows, cols] for label indexing and .iloc for position indexing.

⚡ Quick check

  • ✓ df.info(), df.describe()
  • ✓ groupby().agg()
  • ✓ pd.get_dummies for one-hot