Learn Before
Activity (Process)

Selecting Rows and Columns in a Pandas DataFrame

A Pandas DataFrame can be subset by column names, row labels, integer positions, or Boolean conditions. Use df["column_name"] to select one column. For explicit two-dimensional selection, .loc uses labels and .iloc uses integer positions; for example, df.iloc[3:5, 0:2] selects rows at positions 3 and 4 and the first two columns. A label slice such as df["20130102":"20130104"] selects rows by index labels, while a condition such as df[df["A"] > 0] filters rows according to column values.

0

0

Updated 2026-08-30

Tags

Python Programming Language

Data Science