pandas: Working With DataFrames

Harry · 14 Sep 2026 · 2 views
Advertisement
Advertisement

What is pandas?

pandas adds two powerful structures: Series (one column) and DataFrame (a table). It is the foundation of Python data work.

pip install pandas

Creating a DataFrame

import pandas as pd

data = {
    "name": ["Priya", "Amit", "Riya"],
    "city": ["Mumbai", "Pune", "Delhi"],
    "score": [88, 92, 79],
}
df = pd.DataFrame(data)
print(df)

Reading Data From Files

df = pd.read_csv("sales.csv")
print(df.head())           # first 5 rows
print(df.describe())       # statistics
print(df["city"].value_counts())

Filtering and Selecting

top = df[df["score"] >= 85]
selected = df[["name", "score"]]
print(top)

Adding Columns and Aggregating

df["bonus"] = df["score"] * 1.1
avg = df.groupby("city")["score"].mean()
print(avg)

Key Points

  • DataFrames feel like a spreadsheet but are fully programmable.
  • Boolean masks (df[df["col"] > x]) filter rows.
  • groupby + an aggregate summarises like SQL GROUP BY.
Share this post:

Comments (0)

Please login or register to comment.