Accessing DataFrame Rows and Columns
DataFrame Access Patterns
Single Column
df['column'] returns a Series; df[['col1', 'col2']] returns a DataFrame.
Row by Label
df.loc['index_label'] returns the row with that index.
Row by Position
df.iloc[0] returns the first row regardless of its label.
Boolean Filter
df[df['col'] > 100] returns rows matching the condition.
Noble Desktop's Python Machine Learning Bootcamp covers scikit-learn, Keras, neural networks, and applied ML projects.
This lesson is a preview from our Data Science & AI Certificate Online (includes software) and Python Certification Online (includes software & exam). Enroll in a course for detailed lessons, live instructor support, and project-based training.
Use .iloc and .loc with correct indexing and slicing to select specific rows and columns from a Pandas DataFrame. Watch this tutorial to learn the key concepts and techniques.