Manipulating pandas data frames is a common task during exploratory analysis or preprocessing in a Data Science project. Filtering and sub-setting the data is also common. Over time, I have found myself needing to select columns based on different criteria. I hope readers find this article as a reference.

Example Data

Selecting columns based on their name

Selecting a subset of columns found in a list

Selecting a subset of columns based on difference of columns

Selecting a subset of columns that is not in a list

Selecting columns based on their data type

Selecting columns based on their column name containing a substring

Selecting columns based on their column name containing a string wildcard

Selecting columns based on how their column name starts

Selecting columns based on how their column name ends

Selecting columns if all rows meet a condition

Selecting columns if any row of a column meets a condition

Selecting columns if the average of rows in a column meet a conditio

#beginner #python #pandas #data-scien #tutorial

Interesting Ways to Select Pandas DataFrame Columns
1.45 GEEK