Selecting
Pandas Basics
1 min read
This section is 1 min read, full guide is 30 min read
Published Sep 29 2025, updated Oct 24 2025
21
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
PandasPython
There are multiple ways to select data depending on whether you want rows, columns, or both, and whether you are selecting by label or position.
Single column
df["Col1"]
Copy to Clipboard
Returns a Series.
Multiple columns
df[["Col1", "Col4"]]
Copy to Clipboard
Returns a DataFrame with the selected columns. Double brackets [[ ]] are required for multiple columns.
By index using .iloc[]
- Select rows by integer position (0-based index).
# first row as Series
df.iloc[0]
# first three rows as DataFrame
df.iloc[0:3]
# first and third rows
df.iloc[[0,2]]
Copy to Clipboard
Toggle show comments
By label using .loc[]
- Select rows (or rows + columns) by index labels.
# row with index label 0
df.loc[0]
# rows with index labels 0,1,2 (inclusive)
df.loc[0:2]
# all rows, only selected columns
df.loc[:, ["Col1","Col4"]]
# subset of rows and columns
df.loc[0:2, ["Col1","Col4"]]
Copy to Clipboard
Toggle show comments
Conditional Selection (Boolean Indexing)
# rows where Col1 > 10
df[df["Col1"] > 10]
# conditional + column selection
df.loc[df["Col1"] > 10, ["Col1","Col4"]]
Copy to Clipboard
Toggle show comments
Single cell .at[] (label-based, single element)
# value at row index 0, column "Col1"
df.at[0, "Col1"]
Copy to Clipboard
Toggle show comments
Single cell .iat[] (integer position, single element)
# value at row 0, column 2 (0-based position)
df.iat[0, 2]
Copy to Clipboard
Toggle show comments
Slicing - Rows
# first 5 rows (like iloc)
df[0:5]
Copy to Clipboard
Toggle show comments
Slicing - Columns
# columns Col1 to Col4 (inclusive)
df.loc[:, "Col1":"Col4"]
Copy to Clipboard
Toggle show comments
Selecting with .filter()
- Useful for selecting columns by names, regex, or like patterns:
# select specific columns
df.filter(items=["Col1","Col4"])
# select columns containing 'Col'
df.filter(like="Col")
# regex-based selection
df.filter(regex="^Col[1-3]$")
Copy to Clipboard
Toggle show comments














