Selecting

Pandas Basics

1 min read

Published Sep 29 2025, updated Aug 17 2026


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 Seriesdf.iloc[0]# first three rows as DataFramedf.iloc[0:3]# first and third rowsdf.iloc[[0,2]]



By label using .loc[]

  • Select rows (or rows + columns) by index labels.
# row with index label 0df.loc[0]# rows with index labels 0,1,2 (inclusive)df.loc[0:2]# all rows, only selected columnsdf.loc[:, ["Col1","Col4"]]  # subset of rows and columnsdf.loc[0:2, ["Col1","Col4"]]



Conditional Selection (Boolean Indexing)

# rows where Col1 > 10df[df["Col1"] > 10]# conditional + column selectiondf.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 columnsdf.filter(items=["Col1","Col4"])# select columns containing 'Col'df.filter(like="Col")   # regex-based selectiondf.filter(regex="^Col[1-3]$")
© 2025 SimpleSteps.guide
AboutFAQPoliciesContact
Pandas Basics | Selecting | SimpleSteps.guide