Page2/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…