Sitemap
TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

23 Efficient Ways of Subsetting a Pandas DataFrame

With Selection, Slicing, Indexing and Filtering

10 min readJun 4, 2021

--

Press enter or click to view image in full size
Photo by Hans-Peter Gauster on Unsplash

In part 1 and part 2, we’ve learned how to inspect, describe and summarize a Pandas DataFrame. Today, we’ll learn how to extract a subset of a Pandas DataFrame. This is very useful because we often want to perform operations on subsets of our data. There are many different ways of subsetting a Pandas DataFrame. You may need to select specific columns with all rows. Sometimes, you want to select specific rows with all columns or select rows and columns that meet a specific criterion, etc.

All different ways of subsetting can be divided into 4 categories: Selection, Slicing, Indexing and Filtering.

Press enter or click to view image in full size
(Image by author)

As you continue reading this post, you’ll learn the differences between these categories.

Before discussing any of the methods of subsetting a data frame, it is worth distinguishing between a Pandas Series object and a Pandas DataFrame object.

Pandas Series and DataFrame objects

The Series and the DataFrame are two main data structures in Pandas. Simply, a Series is…

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Rukshan Pramoditha
Rukshan Pramoditha

Written by Rukshan Pramoditha

3,000,000+ Views | BSc in Stats (University of Colombo, Sri Lanka) | Top 50 Data Science, AI/ML Technical Writer on Medium

Responses (4)