Selecting

Pandas Basics

1 min read

Published Sep 29 2025, updated Oct 24 2025


21
0
0
0

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"]

Returns a Series.




Multiple columns

df[["Col1", "Col4"]]

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]]



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"]]



Conditional Selection (Boolean Indexing)

# rows where Col1 > 10
df[df["Col1"] > 10]

# conditional + column selection
df.loc[df["Col1"] > 10, ["Col1","Col4"]]



Single cell .at[] (label-based, single element)

# value at row index 0, column "Col1"
df.at[0, "Col1"]



Single cell .iat[] (integer position, single element)

# value at row 0, column 2 (0-based position)
df.iat[0, 2]



Slicing - Rows

# first 5 rows (like iloc)
df[0:5]



Slicing - Columns

# columns Col1 to Col4 (inclusive)
df.loc[:, "Col1":"Col4"]



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]$")

Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact