2/14
DataFrames β€” Your Data Table Β· Page 2 of 3

Selecting & Filtering Data

Selecting & Filtering Data

This is where Pandas shines β€” powerful, expressive data querying.

Column Selection

df["name"]            # single column β†’ Series
df[["name", "score"]] # multiple columns β†’ DataFrame

Row Selection with .loc and .iloc

df.loc[0]          # row by label/index
df.loc[0:2]        # rows 0 to 2 (inclusive)
df.iloc[0]         # row by integer position
df.iloc[0:3]       # rows 0, 1, 2

Boolean Filtering (Most Common)

# Single condition
df[df["score"] > 90]

# Multiple conditions (use & and |)
df[(df["age"] >= 22) & (df["gpa"] > 3.5)]

# Using .query() β€” very readable
df.query("age >= 22 and gpa > 3.5")

.isin() β€” Match Multiple Values

df[df["major"].isin(["CS", "Math"])]

πŸ’‘ Boolean filters return a new DataFrame β€” they never modify the original.

main.py
Loading...
OUTPUT
β–ΆClick "Run Code" to execute…